A matlab warning on solving equations

Click For Summary
SUMMARY

The discussion addresses a syntax error encountered in MATLAB when attempting to solve the equation 'x^2 + 9*x – 7 = 0' using the solve function. The error arises from the incorrect use of the equation format. The correct syntax requires the use of '==' instead of '='. The solution is achieved by defining the variable with 'syms x' and using 'solve('x^2+9*x-7==0',x)', which yields two solutions: approximately 0.7202 and -9.7202.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of symbolic mathematics in MATLAB
  • Knowledge of solving algebraic equations
  • Experience with MATLAB's 'syms' and 'solve' functions
NEXT STEPS
  • Explore MATLAB's symbolic toolbox for advanced equation solving
  • Learn about MATLAB's error handling and debugging techniques
  • Research the differences between '=' and '==' in MATLAB
  • Investigate numerical methods for solving equations in MATLAB
USEFUL FOR

Students, engineers, and researchers who are using MATLAB for mathematical modeling and equation solving will benefit from this discussion.

mech-eng
Messages
826
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

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K