Solve and graph a cubic equation with parameter

5 ビュー (過去 30 日間)
charlotte88
charlotte88 2016 年 2 月 1 日
コメント済み: John D'Errico 2020 年 11 月 24 日
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!

回答 (1 件)

John D'Errico
John D'Errico 2016 年 2 月 1 日
編集済み: John D'Errico 2020 年 11 月 24 日
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 件のコメント
Tom Cattani
Tom Cattani 2020 年 11 月 23 日
this doesn't work
John D'Errico
John D'Errico 2020 年 11 月 24 日
Note the addition of the 'maxdegree' flag. That will probably improve the behavior for you.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by