[Math] Is this Hermite interpolation correct

algorithmsinterpolationnumerical methods

Someone can explain this hermit interpolation algorithm with example?

Thank you,

function [H]=hermite(X,x,f,fd);
m=length(x);
for i=1:m
    z(2*i-1)=x(i);
    Q(2*i-1,1)=f(i);
    z(2*i)=x(i);
    Q(2*i,1)=f(i);
    Q(2*i,2)=fd(i); 
    if i~=1
        Q(2*i-1,2)=(Q(2*i-1,1)-Q(2*i-2,1))/(z(2*i-1)-z(2*i-2));
    end;
end;
for i=3:2*m
    for j=3:i
        Q(i,j)=(Q(i,j-1)-Q(i-1,j-1))/(z(i)-z(i-j+1));
    end
end
p=1;
H=Q(1,1);
for i=2:2*m
    p=p.*(X-z(i-1));
    H=H+p.*Q(i,i);
end;

Best Answer

The next time you post raw code, please show the basic courtesy of telling us what language it's in.

You'll find an explanation of the algorithm underlying this code together with an example in the Wikipedia article on Hermite interpolation, unsurprisingly. Also take note of the article on divided differences that it links to. If there is something in those articles that you don't understand, please ask a specific question about that particular aspect.

Related Question