Why the results are different when use different letters?

조회 수: 2 (최근 30일)
Xizeng Feng
Xizeng Feng 2022년 3월 11일
댓글: Xizeng Feng 2022년 3월 14일
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

채택된 답변

Walter Roberson
Walter Roberson 2022년 3월 12일
You are not specifying which two variables to solve for, so solve() is using symvar() and picking the first two variables.
With the different names involved, the relative order of the variables in symvar() is different than you are expecting.
  댓글 수: 3
Walter Roberson
Walter Roberson 2022년 3월 12일
syms rs xs rp xp
[rp,xp]=solve(rs*rp^2+rs*xp^2==rp^2*xp, xs*rp^2+xs*xp^2==xp^2*rp, [rp, xp])
rp = 
xp = 
Xizeng Feng
Xizeng Feng 2022년 3월 13일
thank you very much for your kindly help. I learned more about the symbolic operations now.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

DGM
DGM 2022년 3월 11일
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.

Jan
Jan 2022년 3월 11일
편집: Jan 2022년 3월 11일
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
Jan
Jan 2022년 3월 13일
It is an important point to see, that the equations are not equal and that spaces around operators do matter.
Xizeng Feng
Xizeng Feng 2022년 3월 14일
Yes, I'll remember this point.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by