getting a wrong solution to a simple linear system using "solve"

I am trying to solve the following simple symbolic singular 6X6 linear system using "solve":
[xx,yy,zz,yz,xz,xy]=solve(' 0*xx -f1*yy + f1*zz + (b1-c1)*yz + d1*xz -e1*xy=0' , 'e1*xx -e1*zz -d1*yz + (c1-a1)*xz + f1*xy=0' , '-d1*xx + d1*yy + e1*yz -f1*xz + (a1-b1)*xy=0'... ,' -f2*yy + f2*zz + (b2-c2)*yz + d2*xz -e2*xy=0' , 'e2*xx -e2*zz -d2*yz + (c2-a2)*xz + f2*xy=0' , '-d2*xx + d2*yy + e2*yz -f2*xz + (a2-b2)*xy=0' )
The correct answer should be xy=yz=xz=0 and xx=yy=zz=z (z free parameter). Instead I am getting xx=yz=xz=z and xy=yy=zz=0.
Why is that?
Also, is there a way to solve symbolicallty using matrices? Something like linsolve with symbolic arguments?
Thanks Uri

 Akzeptierte Antwort

Friedrich
Friedrich am 1 Apr. 2011
Hi Uri,
this is because you are using a wrong syntax for your problem. With the following syntax everything works fine
sol =solve(' 0*xx -f1*yy + f1*zz + (b1-c1)*yz + d1*xz -e1*xy=0' , 'e1*xx -e1*zz -d1*yz + (c1-a1)*xz + f1*xy=0' , '-d1*xx + d1*yy + e1*yz -f1*xz + (a1-b1)*xy=0'...
,' -f2*yy + f2*zz + (b2-c2)*yz + d2*xz -e2*xy=0' , 'e2*xx -e2*zz -d2*yz + (c2-a2)*xz + f2*xy=0' , '-d2*xx + d2*yy + e2*yz -f2*xz + (a2-b2)*xy=0' );
xx = sol.xx
yy = sol.yy
zz = sol.zz
xy = sol.xy
yz = sol.yz
xz = sol.xz
This behavior is also stated in the documentation:
For a system of equations and an equal number of outputs, the results are sorted alphabetically and assigned to the outputs.
I hope I could help,
Friedrich

1 Kommentar

Thank you Fredrich! This does help.
In this syntax, where are the unknowns declared? How does matlab know, for example, to solve for xx and not for a1?
Can I give "solve" input in matrix form? for example provide a 6X6 matrix with the coefficients a1..f2 ?
Thanks again
Uri

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Friedrich
Friedrich am 1 Apr. 2011
I think that MATLAB gues the right values is a little bit luck. Normally you would specify what you want to solve:
sol =solve(' 0*xx -f1*yy + f1*zz + (b1-c1)*yz + d1*xz -e1*xy=0' , 'e1*xx -e1*zz -d1*yz + (c1-a1)*xz + f1*xy=0' , '-d1*xx + d1*yy + e1*yz -f1*xz + (a1-b1)*xy=0'...
,' -f2*yy + f2*zz + (b2-c2)*yz + d2*xz -e2*xy=0' , 'e2*xx -e2*zz -d2*yz + (c2-a2)*xz + f2*xy=0' , '-d2*xx + d2*yy + e2*yz -f2*xz + (a2-b2)*xy=0','xx','yy','zz','xy','yz','xz');
xx = sol.xx
yy = sol.yy
zz = sol.zz
xy = sol.xy
yz = sol.yz
xz = sol.xz
I think you can pass a matrix to solve. This works for me:
>> syms a b c d
>> A = [a b ; c d],
>> sol = solve(A)
Friedrich

2 Kommentare

I see. Thanks.
I tied to copy-paste the matrix form into the command window, but I am getting the following error:
??? Error using ==> sym.maple
at offset 26, `;` unexpected
Error in ==> sym.transpose at 18
B = maple('transpose',A);
Error in ==> sym.findsym at 26
sc = char(S(:).');
Error in ==> solve at 99
vars = ['[' findsym(sym(eqns),neqns) ']'];
Error in ==> sym.solve at 49
[varargout{1:max(1,nargout)}] = solve(S{:});
Did you actually try to run this and got it to work?
Thanks
Uri
Yes i tried it and it works fine:
syms a b c d
A = [a b ; c d],
sol = solve(A)
A =
[ a, b]
[ c, d]
sol =
a: [1x1 sym]
b: [1x1 sym]
c: [1x1 sym]
d: [1x1 sym]
I am using Matlab R2010b and Win7 64bit.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by