How can I find roots of cubic function?

23 views (last 30 days)
Lawrence Besong
Lawrence Besong on 10 Apr 2018
Answered: Walter Roberson on 10 Apr 2018
I have a 3 x 3 matrix and with position (1,1) "x" as an unknown variable, after I solved for the invariants my cubic functions becomes y^3 - (x+50)y^2 +(500x -5200)y + (3600x) = 0. How can I solve for the roots in terms of x on matlab?

Answers (4)

James Tursa
James Tursa on 10 Apr 2018
Do you mean like this?
syms x y
solve('y^3 - (x+50)*y^2 +(500*x -5200)*y + (3600*x) = 0',y)
  1 Comment
Walter Roberson
Walter Roberson on 10 Apr 2018
Edited: Walter Roberson on 10 Apr 2018
Note that this will fail in R2018a, which no longer permits strings for equations to be solved. But the error message it gives will be misleading: "List of equations must not be empty."
Replacement is
solve(y^3 - (x+50)*y^2 +(500*x -5200)*y + (3600*x),y)

Sign in to comment.


Star Strider
Star Strider on 10 Apr 2018
Edited: Star Strider on 10 Apr 2018
One approach:
syms x y
Eqn = y^3 - (x+50)*y^2 +(500*x -5200)*y + (3600*x) == 0;
X = solve(Eqn, x)
X_fcn = matlabFunction(X)
Y = vpasolve(X,y)
X =
(- y^3 + 50*y^2 + 5200*y)/(- y^2 + 500*y + 3600)
X_fcn =
function_handle with value:
@(y)(y.*5.2e3+y.^2.*5.0e1-y.^3)./(y.*5.0e2-y.^2+3.6e3)
Y =
-51.321687612368740126279743503002
0
101.321687612368740126279743503
EDIT
Solving in terms of ‘x’:
S = vpasolve(Eqn,y)
yields:
S =
root(z^3 - z^2*(x + 50) + z*(500*x - 5200) + 3600*x, z, 1)
so the solutions are the roots of the ‘z’ polynomial.

Lawrence Besong
Lawrence Besong on 10 Apr 2018
Is it possible to find the roots in terms of "x"?

Walter Roberson
Walter Roberson on 10 Apr 2018
solve(y^3 - (x+50)*y^2 +(500*x -5200)*y + (3600*x),y)
or
isolate(y^3 - (x+50)*y^2 +(500*x -5200)*y + (3600*x)==0, y)
if you use solve() then you will get
root(z^3 - z^2*(x + 50) + z*(500*x - 5200) + 3600*x, z, 1)
root(z^3 - z^2*(x + 50) + z*(500*x - 5200) + 3600*x, z, 2)
root(z^3 - z^2*(x + 50) + z*(500*x - 5200) + 3600*x, z, 3)
which is the set of three different specific roots of the cubic; isolate() will say
y == root(z^3 - z^2*(x + 50) + z*(500*x - 5200) + 3600*x, z, 1)
which is only in terms of the primary root. This is documented: "For equations with multiple solutions, isolate returns the simplest solution."

Community Treasure Hunt

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

Start Hunting!