其他分享
首页 > 其他分享> > matlab关于牛顿插值法的简单应用

matlab关于牛顿插值法的简单应用

作者:互联网

问题
差商表

差值多项式


X=[1,2,3,4,5,6]; %X矩阵
Y=X.^3-4.*X;     %Y矩阵
N=6      %总共六个结点
f=zeros(N,N); %建立一个N维零方阵

for k = 1 : N
    f(k,1)=Y(1,k); %先给第一列赋值Y

end
 
for i = 2:N   %列
    for k = i:N %行
        
        f(k,i)=(f(k,i-1)-f(k-1,i-1))/(X(k)-X(k-i+1));  
        %这个X(k-i+1)要仔细琢磨一下其余的直接抄公式
        

    end
end
syms x;
y=Y(1)+f(2,2)*(x-1)+f(3,3)*(x-1)*(x-2)+f(4,4)*(x-1)*(x-2)*(x-3);


再举一个例子
用牛顿差值公式计算ln(0.54)

X=[0.4,0.5,0.6,0.7,0.8];
Y=[-0.916291,-0.693147,-0.510826,-0.357765,-0.223144];
N=5
f=zeros(N,N);

for k = 1 : N
f(k,1)=Y(1,k);

end

for i = 2:N %列
for k = i:N %行

    f(k,i)=(f(k,i-1)-f(k-1,i-1))/(X(k)-X(k-i+1));
    

end

end
x=0.54;
y=Y(1)+f(2,2)(x-0.4)+f(3,3)(x-0.4)(x-0.5)+f(4,4)(x-0.4)(x-0.5)(x-0.6)+…
f(5,5)(x-0.4)(x-0.5)(x-0.6)(x-0.7);

标签:end,插值法,牛顿,0.5,0.4,0.7,0.6,zeros,matlab
来源: https://blog.csdn.net/JIAHAORA/article/details/121097966