Solve and graph a cubic equation with parameter

7 visualizaciones (últimos 30 días)
charlotte88
charlotte88 el 1 de Feb. de 2016
Comentada: John D'Errico el 24 de Nov. de 2020
Hi everyone,
I am pretty new with matlab, and right now I am a bit lost. I want to solve the following cubic equation:
-16x^3 + (14-2w)x^2 - (4/3)x - (w/9 + 5/27) = 0
w is a parameter between 0 and 1. I only want the solutions where x is between 0 and 1. What I would like is to plot x when w varies between 0 and 1, let's say starting from 0 and increasing by 0.1.
I have found that roots can solve the function for me, but I am not sure how to get a graph out of it.
Help would be much appreciated!

Respuestas (1)

John D'Errico
John D'Errico el 1 de Feb. de 2016
Editada: John D'Errico el 24 de Nov. de 2020
Easy, peasy. However, I would not use roots for that, as it will not allow you to distinguish the various roots as they cross paths. As well, it will force you to do the solves in a loop.
syms x w
x_w = solve(-16*x^3 + (14-2*w)*x^2 - (4/3)*x - (w/9 + 5/27) == 0,x,'maxdegree',3);
ezplot(vpa(x_w(1)),[0,1])
ezplot(vpa(x_w(2)),[0,1])
ezplot(vpa(x_w(3)),[0,1])
I won't actually include the graphs here though.
I would point out that you need to remember to use * when you multiply. That is, 2w is not a valid MATLAB expression.
  2 comentarios
Tom Cattani
Tom Cattani el 23 de Nov. de 2020
this doesn't work
John D'Errico
John D'Errico el 24 de Nov. de 2020
Note the addition of the 'maxdegree' flag. That will probably improve the behavior for you.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by