solve() returns the symbol not the solution

I am trying to use solve() and it does not seem to be working. It keeps returning the symbol I am solving for, not a solution. I tried using sample code from the documentation and it still gives the same answer.
syms a b c x
eqn = a*x^2 + b*x + c == 0;
solx = solve(eqn, x)
solx =
x

답변 (1개)

Star Strider
Star Strider 2015년 3월 15일

1 개 추천

It returns exactly what it should:
solx =
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
If you want a numeric answer, you have to supply numeric values for ‘a’, ‘b’, and ‘c’. (You might also want to use the vpasolve function if you want a strictly numeric result.)

댓글 수: 3

John D'Errico
John D'Errico 2015년 3월 15일
편집: John D'Errico 2015년 3월 15일
While Star is exactly correct here, that solve SHOULD return the solution as shown, IF Ryan is getting solx == x, then most likely he has messed up the expression stored in eqn, as otherwise, solve would have been successful. This is a common error, for someone to not realize that they do not have what they think is stored in a variable. Since MATLAB will never lie, the implication is Ryan must be mistaken as to what is in those variables. +1 anyway.
Ryan Good
Ryan Good 2015년 3월 16일
What I posted was copy and pasted from the documentation, there is no mistake in Eqn. The answer is the last line , solx = x. I did not get the -(b + (b^2 - 4*a*c)^(1/2))/(2*a) answer as Star returned.
It seems I must have a problem with the symbolic package. MuPad is missing as well.
To find out if you have the Symbolic Math Toolbox, type:
ver
in the Command Window. If you have the Toolbox, it should be listed.
If it is listed, and you still cannot access its functions, type in the Command Window:
restoredefaultpath
rehash toolboxcache
then see if your code works.
If you’re still having problems after that, contact MathWorks Technical Support.

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2015년 3월 15일

댓글:

2015년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by