MATLAB A matlab warning on solving equations

AI Thread Summary
The discussion revolves around an error encountered while attempting to solve the quadratic equation 'x^2 + 9*x - 7 = 0' using the 'solve' function. The error message indicates that the equation is not recognized as a valid expression. The solution involves using the correct syntax by defining the variable with 'syms x' and formatting the equation as 'x^2 + 9*x - 7 == 0'. This approach successfully returns the roots of the equation, which are approximately 0.7202 and -9.7202 after evaluation. The key takeaway is the importance of using the correct syntax for symbolic equations in mathematical software.
mech-eng
Messages
825
Reaction score
13
Hi,
>> d = 'x^2 + 9*x –7 = 0';
>> solve(d)
Error using solve>processString (line 354)
' x^2 + 9*x –7 = 0 ' is not a valid expression or equation.

Error in solve>getEqns (line 284)
eqns = processString(eqns, v, vc);

Error in solve (line 160)
[eqns,vars,options] = getEqns(varargin{:});

I can not understand what is the problem here?
 
Physics news on Phys.org
You aren't using the right syntax.
Code:
syms x
solve('x^2+9*x-7==0',x)
 
ans =
 
   109^(1/2)/2 - 9/2
 - 109^(1/2)/2 - 9/2

eval(ans)

ans =

    0.7202
   -9.7202
 

Similar threads

Back
Top