Matlab:绘制y值范围的立方函数

时间:2015-12-01 11:21:54

标签: matlab cubic

我有一个三次方程式:

roots([9E-10 -2E-06 0.0014 0.039])

我试图绘制y值为0.0到0.5的等式(我知道它给出了0到700范围内的x值。(即该等式已经适合这个数据)

r=0.0039-y; %where y ranges from 0.0 to 0.5
[eqnroots]=roots([9E-10 -2E-06 0.0014 r])

我使用

找到真正的根
isreal(eqnroots(n));

然后绘制方程,但它没有给出正确的x / y范围,并且看起来很合适。

1 个答案:

答案 0 :(得分:3)

roots函数仅产生多项式方程的根。要为给定的x值集生成所有y值,您需要使用polyval

试试这个:

% Polynomial coefficients
p = [9E-10 -2E-06 0.0014 0.039];

% Generate y-values for x-range we are interested in
x = -270:0.1:1350;
y = polyval(p,x);

% Find roots of the polynomial.
% Select any where the imaginary component is negligible, i.e. it is real.
% As it's a root, the corresponding y-value will be 0.
xroot = roots(p);
xroot = xroot(abs(imag(xroot)) < 1e-10);
yroot = zeros(size(xroot));

% Plot the polynomial and its real roots.
figure;
hold on
plot(x,y, 'b')
plot(xroot,yroot, 'rx')

这给出了以下图:

enter image description here

相关问题