1. Math
  2. Advanced Math
  3. lagrange polynomial algorithm by neville interpolation at a vector of...

Question: lagrange polynomial algorithm by neville interpolation at a vector of...

Question details

%Lagrange Polynomial Algorithm by
%Neville Interpolation at a vector of %points.
clc;
clear;
format long
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Input
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n = input('Enter the number of points to interpolate at: ');
x = input('Enter the vector of points to interpolate at: ');

d = input('Enter the vector of function values of interpolation points: ');
t = input('Enter the value to approximate the function at: ');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Neville Method
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q = zeros(n,n); %Initializes an n x n matrix
Q(:,1) = d'; %Enters the vector of

% function values as the first column of Q.

for i = 2:n
for j = 2:i
Q(i,j) =[(t - x(i - 1))*Q(i,j-1) - (t - x(i))*Q(i-1,j-1)]/(x(i) - x(i-1));
end
end
%Q(i,j) calculates the polynomial approximation for each matrix point.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Output%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q%Displays the complete matrix Q.
P = input('Enter the point in the matrix to be outputed: ');
disp('The value of the polynomial is approximately: ')
disp(P) %Displays the function approximation for that Lagrange
%polynomial.3. EXPERIMENTAL SECTION: For the following exercises you can adapt the following code, which im plements Nevilles Algorithm for the generation of the Lagrange poly- nomials %Lagrange Polynomial Algorithm by %Neville Interpolation at a vector of %points. clear; format long XXXXXXXXXXXXX:ににに1XXXXXXXXXXXXXXXX:にににに1. %input eele oeeele9e9lel9lelelelelalleleldelal n- input (Enter the number of points to interpolate at: x - input (Enter the vector of points to interpolate at:); d -input Enter the vector of function values of interpolation points: t-input (Enter the value to approximate the function at: ); %Neville Method yXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:に1:1XX. Q = zeros (n,n); %Initializes an n x n matrix Q(: ,1) -d; %Enters the vector of%input 9l9lleTellle999991T&T79799999 n - input (Enter the number of points to interpolate at: ); x = input (Enter the vector of points to interpolate at: ,); d -input (Enter the vector of function values of interpolation points: ); t-input (Enter the value to approximate the function at: ); 9l9lleTellle999991T&T79799999 %Neville Method 9l9lleTellle999991T&T79799999 Q = zeros (n , n); %Initializes an n x n matrix Q(: ,1) = d; %Enters the vector of % function values as the first column of Q for j 2:i end end %Q(i,j) calculates the polynomial approximation for each matrix point. ·に/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:1:1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. %Output% ·に/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:に/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. Q %Displays the complete matrix Q P - input (Enter the point in the matrix to be outputed: ); disp (The value of the polynomial is approximately) disp(P) %Displays the function approximation for that Lagrange(b) Use appropriate Lagrange interpolation polynomials of degree one, two three and four to approximate each of the following i. f(8.4) if f(8) 16.63553, f(8.1) 17.61549, f(8.3) 17.56492, f(8.6) 18.50515, f (8.7) 18.82091. ii. f(-1/3) if f(-1)-0.10000000, f(-0.75)--0.07181250, f(-0.5-0.02475000, f(-0.25) 1.10100000 0.33493750, f(0)

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution