我想在 matlab 中绘制三次方程 x^{3}+Ax^{2}+1=0 的根。我知道 A<-1.88 有 3 个实根,如果 A>-1.88 则有 1 个实根。我想绘制 3 个实根作为 A 的函数,当它切换到 1 个实根和 2 个复数以绘制实根和复数共轭解的实部时,它们都在同一个图中(可能是 2-3图表)。
虽然我是一个 matlab 初学者。我试过了
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])
但是 vpa 不知道如何对 r 进行数值计算。
最佳答案
不需要为此做符号数学,
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');
关于matlab - 在 matlab 中绘制立方根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54121576/