Need help solving a quadratic function

5 views (last 30 days)
I need to solve a quadratic equation in matlab, to do that I tried to use syms('x') to use x to solve the quadratic equation, but when I do this I keep getting an error message that says
Undefined function 'sym' for input arguments of type 'char'.
Error in solution (line 13)
x=sym('x')
This is what I have in the script so far, I already have a,b,and c defined, I just need to solve for x in the equation and use that to solve for t1 and t2
x=sym('x');
eqn = a*x^2+b*x+c==0;
t=solve(eqn);
t1 = min(t);
t2 = max(t);
This works fine in MATLAB, but when I try and use in MATLAB grader I keep getting the above error message

Answers (1)

Walter Roberson
Walter Roberson on 2 Feb 2022
It appears to me that your instructor has not selected Symbolic Mathematics Toolbox as being active for the purpose of grading.
If the instructor is expecting symbolic output, then the instructor will need to change that.
If the instructor is expecting numeric output, then you will need to change your computation method. For example you could potentially use roots() or use the standard quadratic closed form solutions.
Note: you are taking min() and max() of the pair of quadratic solutions. That is a problem if the solutions use unresolved symbolic variables, or if the solutions are complex valued.
  1 Comment
Cris LaPierre
Cris LaPierre on 2 Feb 2022
Just reinforcing Walter's answer. It would appear you instructor has not included the symbolic toolbox in the products you can use in this course. You will most likely need to actually code up the quadratic equation.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!