MATLAB Answers


How to solve a 2nd degree equation of matrix ?

Asked by Tahn
on 26 May 2013


Pretty new with matlab, I'd like to know how to solve a second-degree equation of matrix : P*B0-P²*C=B1 All of the variables are 7*7 matrix, and I'm looking for P.

I used


I get a result, but it's mainly with NaN and Inf. As it shouldn't be the case, I guess my method isn't the right one, but I've no clue how to do it, and google doesn't really help.

So I'm counting on you !

Thanks !



No products are associated with this question.

3 Answers

Answer by Stephan M. H.
on 26 May 2013


Unfortunately you didn't specify what you have and how you defined it but...

the function solve needs symbolic arguments, i.e., you need to create all matrices with the commands sym or syms

The values of B and C matrices should be given to you. The unkown P you could define by (e.g., 2x2 matrix)

 syms p1 p2 p3 p4
 P_s = sym([p1 p2; p3 p4])
 B0_s = sym(B0)

Then use

 RES = solve(P*B0-P^2*C==B1)        % (without '...')

The command subs is only needed if you don't have values for the B and C matrices.

Hope this helps,



Answer by Tahn
on 26 May 2013
Edited by Tahn
on 26 May 2013

Thanks for your answer, I'm going to try it right away.

My bad, I didn't specify that I defined B0, B1 and C (Basically, withtout the command sym, just with :

 B0 = [1,-0.4,0.44,0,0,0,0;0,1 ...]

So I have to define p1 until p49, and then write

 P_s=sym(p1...p49) ?

That seems pretty long though ! But doable, so let's see !

Edit : my bad, I read too fast and didn't understood what sym did. I just have to rewrite P with all the baby variables inside, and change the form of the 3 know matrix with sym.


Answer by Tahn
on 26 May 2013

After about 45 minutes of calculation, it still didn't work :( :

 >> RES = solve(P_s*B0_s-P_s^2*C_s==B1_s)
 Warning: Solutions might be lost. [solvelib::allvalues_warning] 
 RES = 
     p1: [1x1 sym]
     p2: [1x1 sym]
     p3: [1x1 sym]
     p48: [1x1 sym]
     p49: [1x1 sym]

Et si je veux voir ce qu'il y a dans p1 :

 >> p1
 p1 =

  1 Comment

I can't help with the first warning, and for the second problem I can only guess what you are writing there in French, but you might want to try


if you used

 syms p1 ....

to define everything, p1 etc. still contain only symbolic values. the results is stored in the structure RES

best, Stephan

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!