matlab中描点及拟合问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 01:26:55
对等距的点x值,从-5到5,间隔为1,y=1/(1+x^2),描出各个点,并且用多项式拟合,画出拟合图线……
各位帮忙

你想用几次多项式拟合 不同的要求结果不一样的

x=-5:5;
y=1+x.^2;y=y.^(-1);
plot(x,y,'o');

n=5;
p=polyfit(x,y,n);
xi=-5:0.01:5;
for b=1:length(xi) yi(b)=polyval(p,xi(b));end;

hold on;
plot(xi,yi)