Why the results are different when use different letters?
Show older comments
I solve same equations in different ketters and got fifferent results as follow:
But rs=a, xs=b, rp=c and xp=d. the equations are same!
>> syms rs xs rp xp;
>> [rp,xp]=solve(rs*rp^2+rs*xp^2==xp^2*rp,xs*rp^2+xs*xp^2==rp^2*xp)
rp =
-(rp*(rs*(rp - rs))^(1/2))/(rp - rs)
(rp*(rs*(rp - rs))^(1/2))/(rp - rs)
xp =
-(rs*(rp - rs))^(1/2)
(rs*(rp - rs))^(1/2)
-------------------------------------------------------------
>> syms a b c d
>> [c,d]=solve(a*c^2+a*d^2==c^2*d,b*c^2+b*d^2==d^2*c)
c =
0
(a^2 + b^2)/b
d =
0
(a^2 + b^2)/a
Accepted Answer
More Answers (2)
DGM
on 11 Mar 2022
They are not the same.
syms rs xs rp xp;
[rp,xp] = solve( rs*rp^2+rs*xp^2 == xp^2*rp, xs*rp^2+xs*xp^2 == rp^2*xp)
syms a b c d
[c,d] = solve( a*c^2+a*d^2 == c^2*d, b*c^2+b*d^2 == d^2*c)
The RHS of both equations don't correspond. You'll have to decide which one is which.
1 Comment
Xizeng Feng
on 13 Mar 2022
Because the equations are different:
syms rs xs rp xp
syms a b c d
[rp, xp] = solve(rs * rp^2 + rs * xp^2 == xp^2 * rp, xs * rp^2 + xs * xp^2 == rp^2 * xp)
[c, d] = solve(a * c^2 + a * d^2 == c^2 * d, b * c^2 + b * d^2 == d^2 * c)
% ^ ?! ^
You see, the replacement is not performed exactly. The term xp is converted twice to c instead of d.
6 Comments
Xizeng Feng
on 12 Mar 2022
Xizeng Feng
on 12 Mar 2022
Edited: Walter Roberson
on 12 Mar 2022
The equations are still not the same. Did you see, that I have inserted spaces around the operators? Note the differences between [a b], [a + b] and [a +b] ! Without a space on the right but one on the left, the + is interpreted as unary operator:
syms a b c d;
[a* c^2 +a*d^2== c^2*d, b* c^2 +b*d^2 ==d^2* c]
syms rs xs rp xp;
[rs*rp^2+rs*xp^2==rp^2*xp, xs*rp^2+xs*xp^2==xp^2*rp]
Xizeng Feng
on 13 Mar 2022
Jan
on 13 Mar 2022
It is an important point to see, that the equations are not equal and that spaces around operators do matter.
Xizeng Feng
on 14 Mar 2022
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






