在Matlab中绘制多项式

时间:2014-04-16 19:46:57

标签: matlab graph plot

function x = plotpint (coef, x1, x2,numpoints) 

%coef: polynom's coefficient array x1,x2 : intervals
%numpoints: the number of data points to be plotted

a=linspace(x1,x2,numpoints); % linspace of intervals and numpoints
b=polyval(coef,a); %values of given coef polynom for intervals
c=polyint(coef); % coef array of given coef's integral of polynom ( don't care here)
d=polyval(c,a); % values of c's polynom(integral of polynom) ( don't care here)
plot(a,b); % plotting polynom and integral of polynom
title('rer'); 

end

我的plotpint功能在这里。例如,我想要p(x)= x ^ 2-4,它有根-2和+2。但是当我试图绘制这个多项式时,我的图表显示root就像图像一样。

enter image description here

我现在该怎么办?我哪里错了?如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

没有问题,您已正确绘制y = x*x + 0*x + 4(根据您coef的值)。

我注意到.0004 * 10^4.0000 * 10^4在缩放级别很难分辨。您可以使用范围-5:5代替-150:150更轻松地查看更详细的信息。

FWIW,在解释MATLAB中的任何图形时,首先要查看轴刻度。

enter image description here