matlab7.0,lagrange插值计算
发布网友
发布时间:2023-01-05 23:52
我来回答
共1个回答
热心网友
时间:2023-10-16 20:04
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
------------------------------------------------------
x=[0.1 0.2 0.15 0 -0.2 0.3];
y=[0.95 0.84 0.86 1.06 1.5 0.72];
x0=[-0.2:0.01:3];
y0=lagrange(x,y,x0);