Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Neville interpolation using MATLAB



MATLAB Program:

% Neville's iterated interpolation algorithm
 % Find the approximate value of f(1.5) from
 % (x,y)= (0,1), (1,e), (2,e^2) & (3,e^3).

 n = input('Enter n for (n+1) nodes, n:  ');
 xx = zeros(1,n+1);
 q = zeros(n+1,n+1);

 for i = 0:n
   fprintf('Enter x(%d) and f(x(%d)) on separate lines:  \n', i, i);
   xx(i+1) = input(' ');
   q(i+1,1) = input(' ');
 end
 x = input('Now enter a point at which to evaluate the polynomial, x = ');
 
 d = zeros(1,n+1);
 d(1) = x-xx(1);
 for i = 1:n
    d(i+1) = x-xx(i+1);
    for j = 1:i
       q(i+1,j+1) = (d(i+1)*q(i,j)-d(i-j+1)*q(i+1,j))/(d(i+1)-d(i-j+1));
    end
 end

 fprintf('Table for interpolation evaluated at x = %11.8f: \n', x);
 for i = 0:n
    fprintf('%11.8f ', xx(i+1));
    for j = 0:i
       fprintf('%11.8f ', q(i+1,j+1));
    end
    fprintf('\n');
 end

OUTPUT:

>> Neville_interpolation
Enter n for (n+1) nodes, n:  3
Enter x(0) and f(x(0)) on separate lines:  
 0
 1
Enter x(1) and f(x(1)) on separate lines:  
 1
 2.7
Enter x(2) and f(x(2)) on separate lines:  
 2
 7.29
Enter x(3) and f(x(3)) on separate lines:  
 3
 19.683
Now enter a point at which to evaluate the polynomial, x = 1.5
Table for interpolation evaluated at x =  1.50000000: 
 0.00000000  1.00000000 
 1.00000000  2.70000000  3.55000000 
 2.00000000  7.29000000  4.99500000  4.63375000 
 3.00000000 19.68300000  1.09350000  4.01962500  4.32668750 
>> 




No comments

Popular Posts

Followers