I am using the command
x = solve('a*x^3 + b*x^2 + c*x + d')
to get the polynomial's roots. It returns a symbolic answer. Then i evaluate the a,b,c,d and i do copy-paste the first symbolic answer and then "enter" to get a numerical answer.
The numbers i get (1 almost real and 2 complex, as it is expected) are not roots of the equation!
I am looking for the poles of a mechanical system, so the roots must exist... What am i doing wrong?

1 Kommentar

Christopher Creutzig
Christopher Creutzig am 29 Aug. 2014
Please provide the values for a, b, c, d with which you run into that problem.
Note that these solution formulas are well known to be numerically unstable. That may be the root of your problem. (No pun intended.)

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 20 Aug. 2014

6 Stimmen

Maybe I’m missing something, but why use the Symbolic Math Toolbox at all for this?
Use the roots function instead:
x = roots([a b c d])

1 Kommentar

Sergio E. Obando
Sergio E. Obando am 7 Jul. 2025
This doc page also offers a discussion on "Roots of Polynomials"

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 7 Jul. 2025

0 Stimmen

syms a b c d x
sol = solve(a*x^3 + b*x^2 + c*x + d, x, 'maxdegree', 3)
sol = 
numsol = subs(sol, [a,b,c,d], [1.5, -2, 3/8, -5]) %substitute in actual values for a b c d
numsol = 
snumsol = simplify(numsol, 'steps', 50)
snumsol = 
double(snumsol)
ans =
2.0237 + 0.0000i -0.3452 - 1.2361i -0.3452 + 1.2361i

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by