这个是实验册上面的实验数据
下面第一段是我的拉格朗日函数m文件
function y=lagrange(x0,y0,x)
n=length(x0);m=length(x);
for i=1:m
z=x(i);
s=0.0;
for k=1:n
p=1.0;
for j=1:n
if j~=k
p = p*(z-x0(j))/(x0(k)-x0(j));
end
end
s=p*y0(k)+s;
end
y(i)=s;
end
**接下来是命令行,对这些实验数据进行拟合,但是发现得到的曲线不对,不知道错在哪里了
x0 = [0.2,0.3,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.05,1.1,1.15,1.2,1.25,1.3,1.35,1.4,1.45];
y0 = [38,58,65,74,85,92,98,108,116,125,135,145,156,168,185,208,244,292,355,405,620,850,1200,1620];
x = linspace(0.2,1.45,24);
y1 = lagrange(x0,y0,x);
plot(x,y1,'g')
hold on
plot(x0,y0,'*')
不知道是什么问题,更接触这个软件,还望各位朋友帮忙看看更正一下,谢谢!!