Matlab can't solve this equation

2 次查看(过去 30 天)
Gianluca
Gianluca 2012-11-12
Hi,
I have an equation with two variables (x,y) and I want to solve it for one of the two variables (y). I wrote this code:
C=3.208; Jacobi constant
M1= 5.9736e24; % Mass of Earth in kg
M2= 7.3477e22; % Mass of Moon in kg
mu=M2/(M1+M2);
syms x y
y=solve(x^2+y^2+2*(1-mu)/sqrt((x+mu)^2 + y^2)+2*mu/sqrt((x-1+mu)^2+y^2)-C, y);
Anyway when I run the script Matlab says:
Warning: Explicit solution could not be found.
> In solve at 83
In equation at 10
I am still learning how to use Matlab, so maybe I am doing something wrong. Does anybody know what's wrong with the code?
Thanks a lot
Gian

回答(2 个)

Jonathan Epperl
Jonathan Epperl 2012-11-12
编辑:Jonathan Epperl 2012-11-12
First of, don't assign the output to y, that might lead to mix-ups, after all y is a dependent variable you might be using again later.
Secondly, there's nothing wrong with your code, your problem is that your equation cannot be solved explicitly, at least not by Matlab (by me neither ;-). I (probably) have a newer version of the Symbolic Toolbox, and I get
F = solve(x^2+y^2+2*(1-mu)/sqrt((x+mu)^2 + y^2)+2*mu/sqrt((x-1+mu)^2+y^2)-C, y);
Warning: The solutions are parametrized by the symbols:
z1 = RootOf(z^8 %... VERY long expression involving z and x)
and
F =
0.0000000000000000017347234759768070944119244813919*(576460752303423488.0*x + 576460752303423488.0*z1 - 569456276141304393.0)^(1/2)*(576460752303423488.0*z1 - 576460752303423488.0*x + 569456276141304393.0)^(1/2)
-0.0000000000000000017347234759768070944119244813919*(576460752303423488.0*x + 576460752303423488.0*z1 - 569456276141304393.0)^(1/2)*(576460752303423488.0*z1 - 576460752303423488.0*x + 569456276141304393.0)^(1/2)
In other words, in order to solve your equation explicitly, Matlab would have to solve an 8-th order polynomial, which is not possible symbolically and so its roots are represented as a parameter z1 in the solution.
I'm not sure where that expression with z and x comes from, but that's probably why there is no call to the numeric solver at this point.
You could try to change your equation by hand a little bit, maybe put it in polar coordinates or something like that?

Walter Roberson
Walter Roberson 2012-11-12
That equation involves solving a polynomial of degree 8. As that is not ameniable to analytic solution, MATLAB attempts to do a numeric solution, but is unable to come up with one due to the presence of the variable "x" in the equation. MATLAB then returns that no explicit solution was found. It would be better if a RootOf() was returned instead, but that does not happen (especially before R2010b.)
y = (-35683896960000/36567140243929-x^2 + (11947200/6047077)*x + RootOf(126341933667992887917257169865924328125*Z^8 + (751910964962903584397247990989198656250*x - 1180461998766305767714643666362521161125)*Z^6 + 6140637045053743106295028206347312500*Z^5 + (-4690165106043173159677104822135769778500*x + 1491615269667830382072291319994700000000*x^2 + 3243059774492681322198866621654800175507)*Z^4 + (24413320515953573444409323967394625000*x - 31682889022049911181469843314314866000)*Z^3 + (-2650902734132599077567116839128671217943 + 6461052414907953754067607308960084929514*x + 986322148827989529893648034960000000000*x^3 - 4658555017613388317895166544987157600000*x^2)*Z^2 + (-63220176859569683563876554297224357000*x + 24264092851692174463638535109400000000*x^2 + 25067134077408890330125934349515421500)*Z + 149227664261398980770788857994625000*x - 72800592265069399531566165702687500)^2, Z)^(1/2)
Together with the negatives of those values.
In the above, RootOf( f(Z), Z) is the set of values, Z, such the f(Z) becomes 0 -- the roots of the expression.
Warning: a small change to the constants you provided, including adding a single decimal more precision, could result in measurably different solution sets.
Caution: for the test values I tried, near x=1, half of the roots were real valued. You cannot just pick a single root and use that: the other roots meet it and take over, with the original root going complex.
  1 个评论
Walter Roberson
Walter Roberson 2012-11-12
Jonathan and I say pretty much the same thing. He typed a bit faster ;-)

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by