I have a problem with the output of solve

조회 수: 3 (최근 30일)
Jürgen
Jürgen 2012년 1월 15일
ello,
I tried to solve an equation
syms x y;
S = solve('x^2 + y^2 = 240^2','x*(s-x)+y*(t-y)-240*sqrt((s-x)^2+(t-y)^2)*0.64279=0')
in this case I get
Warning: Warning, solutions may have been lost
S =
x: [4x1 sym]
y: [4x1 sym]
S.x en S.y contains a very long equation that I can not directly convert to a number, but by pasting it in the command window I can find the values
the strange thing is if I replace s en t by their values I get other solutions
syms x y;
S = solve('x^2 + y^2 = 240^2','x*(279.8-x)+y*(-528.05 -y)-240*sqrt((279.8-x)^2+(-528.05 -y)^2)*0.64279=0')
and these are the correct solutions,
x=double(S.x)
y=double(S.y)
x =
-17.428
207.85
y =
-239.37
-120
so why do I get other solutions if I use s and t as a variable? and even stranger, if I replace 0.64279 by the cosinus of an angle than it thus work at all?
any ideas? probaly I am making a mistake somewhere? So wy is my solutions S.x and S.y not available as a number but as an expression, and how can I convert it?

채택된 답변

Walter Roberson
Walter Roberson 2012년 1월 16일
Because you are sending quoted strings to solve(), x, y, s and t will all be treated as symbolic variables. The S.x, S.y you get out will be symbolic formula in the symbolic variables s and t. You cannot just double() to get values: you have to subs() in values for s and t and then you can double()
The symbolic expression you get out is a quartic (degree 4), so 4 solutions is proper.
x = 154.2671257, y = 183.85226111
x = -238.7563737, y = -24.40069805
x = 207.8465888, y = -119.9991483
x = -17.42811880, y = -239.3663732
MuPAD is known to lose solutions for polynomials in versions up to at least R2010b.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by