[英]solving a quadratic equation with matrices in matlab
I'm trying to numerically find the solution to X^2+X+C=0
where C is the matrix C=[-6,-5;0,-6]
and 0=[0,0;0,0]
, a quadratic equation where the variable is 2x2 matrix. 我试图从数值上找到X^2+X+C=0
的解决方案,其中C是矩阵C=[-6,-5;0,-6]
和0=[0,0;0,0]
,变量为2x2矩阵的二次方程。
So I wrote the following matlab commands 所以我写了下面的matlab命令
C=[-6,-5;0,-6]
[X1,F,e_flag]=fsolve('X^2+X+C',[1,1;1,1])
where [1,1;1,1]
is our initial estimate, or X0
. 其中[1,1;1,1]
是我们的初始估算值,或X0
。
I'm getting the following errors 我收到以下错误
"Error using inlineeval (line 15) Error in inline expression ==> X^2+X+C Undefined function or variable 'X'. “使用inlineeval出错(第15行)内联表达式出错==> X ^ 2 + X + C未定义的函数或变量'X'。
Error in inline/feval (line 34) INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr); 内联/插入错误(第34行)INLINE_OUT_ = inlineeval(INLINE_INPUTS_,INLINE_OBJ_.inputExpr,INLINE_OBJ_.expr);
Error in fsolve (line 218) fuser = feval(funfcn{3},x,varargin{:}); fsolve(第218行)的融合器错误= feval(funfcn {3},x,varargin {:});
Caused by: Failure in initial user-supplied objective function evaluation. 原因:最初的用户提供的目标函数评估失败。 FSOLVE cannot continue." FSOLVE无法继续。”
How do I use fsolve to solve these kind of problems? 我如何使用fsolve解决此类问题?
I don't think fsolve
can be used with a string representation of your equation. 我认为fsolve
不能与方程式的字符串表示形式一起使用。 You should rather pass a function handle to the solver like this: 您应该像这样将函数句柄传递给求解器:
C = [-6,-5;0,-6];
[X1,F,e_flag] = fsolve(@(X) X^2+X+C,[1,1;1,1]);
It also depends on what you mean by: X^2
. 它还取决于您的意思: X^2
。 In Matlab this means the matrix product X*X
. 在Matlab中,这意味着矩阵乘积X*X
If you want entry-wise squaring you should use X.^2
, in which case you will have four independent quadratic equations, which you could solve independently. 如果要进行逐级平方运算,则应使用X.^2
,在这种情况下,将有四个独立的二次方程式,可以独立求解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.