newton forward interpolation method by using less number of for loops
1 回表示 (過去 30 日間)
古いコメントを表示
I wrote the following program for newton forward interpolation method. Can it be written with reduced code using single for loop
function [ yval ] = new_fint( xd,yd,x )
%NEWTON FORWARD Summary of this function goes here
% Detailed explanation goes here
n=length(xd);
if(length(yd)==n)
l=zeros(1,n);
diff=yd';
for j=2:n
for i=1:n-j+1
diff(i,j)=diff(i+1,j-1)-diff(i,j-1);
end
end
l=diff(1,:);
h=xd(2)-xd(1);
u=(x-xd(1))/h;
t(1)=1;
for i=2:n
t(i)=t(i-1)*(u-(i-2))/(i-1);
end
yval=sum(l.*t);
else
error('xd and yd must be of same size');
end
end
回答 (1 件)
KSSV
2018 年 8 月 28 日
This loop can be replaced:
for j=2:n
for i=1:n-j+1
diff(i,j)=diff(i+1,j-1)-diff(i,j-1);
end
end
with:
j=2:n
i=1:n-j+1
diff(i,j)=diff(i+1,j-1)-diff(i,j-1);
Try tit out...and follow the others.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Systems of Nonlinear Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!