1
votes

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.

So I wrote the following matlab commands

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.

I'm getting the following errors

"Error using inlineeval (line 15) Error in inline expression ==> X^2+X+C Undefined function or variable 'X'.

Error in inline/feval (line 34) INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);

Error in fsolve (line 218) fuser = feval(funfcn{3},x,varargin{:});

Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue."

How do I use fsolve to solve these kind of problems?

1

1 Answers

2
votes

I don't think fsolve can be used with a string representation of your equation. 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. In Matlab this means the matrix product 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.