Solve and graph a cubic equation with parameter
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposte (1)
John D'Errico
il 1 Feb 2016
Modificato: John D'Errico
il 24 Nov 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 Commenti
John D'Errico
il 24 Nov 2020
Note the addition of the 'maxdegree' flag. That will probably improve the behavior for you.
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!