How to simplify two symbolic equations and ensure selected variables are not contained in the equation?

조회 수: 6 (최근 30일)
I am a beginner in MatLab and I need some advice. My goal is to come up with an equation for x0 that does not contain h0 and an equation for h0 that does not contain x0. How can I get MatLab to do this automatically?
I have given it a try as below, but the equations I obtained are different from the ones I obtained by hand.
syms x0 h0
[x0 h0] = solve ('(a/2)*(0-x0)^2-h0=0', '(a/2)*(L-x0)^2-h0-h=0')
x0 =
(L^2*a)/2 + 2^(1/2)*L*a*(h0/a)^(1/2)
(L^2*a)/2 - 2^(1/2)*L*a*(h0/a)^(1/2)
h0 =
-2^(1/2)*(h0/a)^(1/2)
2^(1/2)*(h0/a)^(1/2)
By hand I can get the following:
x0 = L/2 - h/(a*L) --(a) h0 = a*L^2/8 + h^2/(2*a*L^2)-h/2 -- (b)
What MatLab commands should I use to get the equations (a) and (b) I determined manually?
Thanks!

답변 (2개)

Mischa Kim
Mischa Kim 2015년 1월 30일
FallGuy, use instead
syms x0 h0
[x0 h0] = solve('(a/2)*(0-x0)^2-h0=0', '(a/2)*(L-x0)^2-h0-h=0',x0,h0)
x0 =
-(- a*L^2 + 2*h)/(2*L*a)
h0 =
(L^4*a^2 - 4*L^2*a*h + 4*h^2)/(8*L^2*a)
Note the additional inputs x0 and h0 in the solve command.

FallGuy
FallGuy 2015년 2월 2일
편집: FallGuy 2015년 2월 2일
Thanks for the input Mischa! Really appreciate it.
I used your formula and I obtained different results:
x0 =
(- a*L^2 + 2*h)^2/(8*L^2*a)
h0 =
-(- a*L^2 + 2*h)/(2*L*a)
Two problems/questions here:
  1. How come Matlab provides different forms of the same solution?
  2. Why is it that the solutions for h0 and x0 are mixed up?
Hope you can enlighten me on the outcomes. Thanks.
  댓글 수: 1
Mischa Kim
Mischa Kim 2015년 2월 2일
In the command window run:
clear % remove all vars from workspace
syms x0 h0
[x0 h0] = solve('(a/2)*(0-x0)^2-h0=0', '(a/2)*(L-x0)^2-h0-h=0',x0,h0)
Copy-paste the above code to make sure you are running the exact same commands.
Also, please add follow-up questions as comments for better readability.

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

Community Treasure Hunt

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

Start Hunting!

Translated by