Solve and graph a cubic equation with parameter
이전 댓글 표시
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
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
2020년 11월 23일
this doesn't work
John D'Errico
2020년 11월 24일
Note the addition of the 'maxdegree' flag. That will probably improve the behavior for you.
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!