Effacer les filtres
Effacer les filtres

newton forward interpolation method by using less number of for loops

1 vue (au cours des 30 derniers jours)
PJS KUMAR
PJS KUMAR le 27 Août 2018
Commenté : PJS KUMAR le 28 Août 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
  1 commentaire
PJS KUMAR
PJS KUMAR le 28 Août 2018
Can we use gamma function to reduce the complexity of the code

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 28 Août 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.

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by