[英]Plot cubic roots in matlab
I would like to plot the roots of the cubic equation x^{3}+Ax^{2}+1=0 in matlab. 我想在matlab中绘制三次方程x ^ {3} + Ax ^ {2} + 1 = 0的根。 I know that there are 3 real roots for A<-1.88 and 1 if A>-1.88.
我知道A <-1.88有3个真正的根,如果A> -1.88则有1个。 I would like to plot the 3 real roots as a function of A and when it switches to 1 real root and 2 complex to plot the real root and the real part of the complex conjugate solutions all in the same plot (perhaps as 2-3 graphs).
我想将3个真实的根作为A的函数绘制,当它切换到1个实根和2个复数时,绘制真实的根和复共轭解的所有部分都在同一个图中(也许是2-3个)图表)。
I am a matlab beginner though. 我是一名matlab初学者。 I tried
我试过了
syms x A
r = solve(x^3 + A*x^2+1 == 0, x);
ezplot(vpa(r(1)),[-10,10])
ezplot(vpa(r(2)),[-10,10])
ezplot(vpa(r(3)),[-10,10])
but vpa doesnt know how to numerically evaluate r. 但vpa不知道如何数字评估r。
There's no need to do symbolic math for this, 没有必要为此做符号数学,
A = (-3:0.01:0)'; % create a vector of values for A
r = arrayfun(@(A)real(roots([1 A 0 1])),A,'uni',false); % calculate the polynomial roots for all values of A
r = [r{:}]; % convert result to a numeric array
plot(A,r'); % plot the result
grid on;
title('Real parts of Polynomial');
xlabel('A');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.