solve() returns the symbol not the solution
8 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Star Strider
2015-3-15
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 个评论
Star Strider
2015-3-16
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!