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 Lagrangec) To approximate the function f()-Vr, we will use the points (1,1 (4,2) and (9,3). i. Write the formula for the Lagrange Polynomial P2(x) that in- terpolates these three points. i. Write a m function file that implements P2(x) using the MAT- LAB polynomial commands iii. To see how well the approximation is Plot f and P2 in the interval [0.0 12. 12. . Plot f -P2 in the interval [0.0 Plot abs((f - P2)./f) in the interval [0.01, 12 iv. Using the plots determine where the approximation is better/worse. v. Why do you get these results? Do they agree with the formula derived in class for the error bound? vi. Add the point (0,0) and repeat (a)-(c). Do you see any im- provement? Deterioration? Where? Why

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