二次牛顿插值多项式程序:x = 05 06 07;y = -0693147 -0510826 -0356675;syms t;p2 = y1 + t-x1y1+1-y1x1+1-x1 + t-x1t-x1+1y1+2-2y1+1+y1factorial2x1+2-x1x1+2-x1+1;p2_value = subsp2t0596输出结果为:p2_value =-05284三次牛顿插值多项式程序:
function [p2_value, p3_value, p4_value] = Newton_Interpolation(x,y,t) % 二次牛顿插值多项式 p2 = y(1) + (t-x(1))(y(1+1)-y(1))/(x(1+1)-x(1)) + (t-x(1))(t-x(1+1))(y(1+2)-2y(1+1)+y(1))/(factorial(2)(x(1+2)-x(1))(x(1+2)-x(1+1))); p2_value = double(subs(p2,t)); % 三次牛顿插值多项式 p3 = y(1) + (t-x(1))(y(1+1)-y(1))/(x(1+1)-x(1)) + (t-x(1))(t-x(1+1))(y(1+2)-2y(1+1)+y(1))/(factorial(2)(x(1+2)-x(1))(x(1+2)-x(1+1))) + (t-x(1))(t-x(1+1))(t-x(1+2))(y(1+3)-3y(1+2)+3y(1+1)-y(1))/(factorial(3)(x(1+3)-x(1))(x(1+3)-x(1+1))(x(1+3)-x(1+2))); p3_value = double(subs(p3,t)); % 四次牛顿插值多项式 p4 = y(1) + (t-x(1))(y(1+1)-y(1))/(x(1+1)-x(1)) + (t-x(1))(t-x(1+1))(y(1+2)-2y(1+1)+y(1))/(factorial(2)(x(1+2)-x(1))(x(1+2)-x(1+1))) + (t-x(1))(t-x(1+1))(t-x(1+2))(y(1+3)-3y(1+2)+3y(1+1)-y(1))/(factorial(3)(x(1+3)-x(1))(x(1+3)-x(1+1))(x(1+3)-x(1+2))) + (t-x(1))(t-x(1+1))(t-x(1+2))(t-x(1+3))(y(1+4)-4y(1+3)+6y(1+2)-4y(1+1)+y(1))/(factorial(4)(x(1+4)-x(1))(x(1+4)-x(1+1))(x(1+4)-x(1+2))*(x(1+4)-x(1+3))); p4_value = double(subs(p4,t)); end
使用示例:
x = [0.5 0.6 0.7 0.8 0.9]; y = [-0.693147 -0.510826 -0.356675 -0.223144 -0.105361]; t = 0.596; [p2_value, p3_value, p4_value] = Newton_Interpolation(x,y,t)
输出结果为:
p2_value = -0.5284 p3_value = -0.5504 p4_value = -0.565
原文地址: https://www.cveoy.top/t/topic/dUgb 著作权归作者所有。请勿转载和采集!