Filter löschen
Filter löschen

newton forward interpolation method by using less number of for loops

2 Ansichten (letzte 30 Tage)
PJS KUMAR
PJS KUMAR am 27 Aug. 2018
Kommentiert: PJS KUMAR am 28 Aug. 2018
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

Antworten (1)

KSSV
KSSV am 28 Aug. 2018
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.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by