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

1 view (last 30 days)
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!

Answers (2)

Mischa Kim
Mischa Kim on 30 Jan 2015
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 on 2 Feb 2015
Edited: FallGuy on 2 Feb 2015
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 Comment
Mischa Kim
Mischa Kim on 2 Feb 2015
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!