用牛顿插值法,计算有点多,编了3个函数都不能用。
i = [-2,-1,-0.5,0.5,1,2];
V = [-637,-96.5,-20.5,20.5,96.5,637];
iNew = 0.1;
%一次插值 选i[3,4]
V1 = b1(V(3))+b2(V(3),i(3),V(4),i(4))*(iNew-i(3));
%二次插值 选i[3,4,5]
V2 = b1(V(3))+b2(V(3),i(3),V(4),i(4))*(iNew-i(3))+b3(V(3),i(3),V(4),i(4),V(5),i(5))*(iNew-i(3))*(iNew-i(4));
function sc3 = b3(f_x1,x1,f_x2,x2,f_x3,x3)
sc3 = (b2(f_x2,x2,f_x3,x3)-b2(f_x1,x1,f_x2,x2))/x3-x1;
end
function sc2 = b2(f_x1,x1,f_x2,x2)
sc2 = (f_x2-f_x1)/(x2-x1);
end
function sc1 = b1(f_x1)
sc1 = f_x1;
end
运行结果及报错内容
函数或变量 'b1' 无法识别。