Need help solving a quadratic function

2 visualizaciones (últimos 30 días)
Michael Eugene Carter
Michael Eugene Carter el 2 de Feb. de 2022
Comentada: Cris LaPierre el 2 de Feb. de 2022
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

Respuestas (1)

Walter Roberson
Walter Roberson el 2 de Feb. de 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 comentario
Cris LaPierre
Cris LaPierre el 2 de Feb. de 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.

Iniciar sesión para comentar.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by