Need help solving a quadratic function

5 ビュー (過去 30 日間)
Michael Eugene Carter
Michael Eugene Carter 2022 年 2 月 2 日
コメント済み: Cris LaPierre 2022 年 2 月 2 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 2 月 2 日
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 件のコメント
Cris LaPierre
Cris LaPierre 2022 年 2 月 2 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by