1. Write a function to evaluate a Lagrange interpolating polynomial at a given value z. Given you have n arbitrary points (xi ; yi) to start with to build the polynomial. Use the algorithm provided for this assignment. To receive full marks you must: • Name of your function must be Lpoly5 • Use the variables in the order they are described in the Algorithm handout for this lab. • Submit the .m file for your function with the correct name. To receive full marks, your function, Lpoly5, but evaluate a polynomial of created from an arbitrary number of starting points (xi ; yi) (n points). This will be tested with data not provided to students. As a test case, you can use the points from the lab handout. Do not submit your results of this case. It is for your assistance only.
function Lpoly5
clear all;
clc;
%n=input('Enter the value of n: ');
%disp('Enter value of x: ')
%for i=1:n
% x(i)=input('x: ');
%end
%disp('Enter value of x: ')
%for i=1:n
% y(i)=input('y: ');
%end
x= [1,2,0,3]
y= [3,2,-4,5]
syms z
sum=0;
d=1;
%z=input('Enter value of z: ')
z=8
fprintf('Coefficients of polynomial by Langrange method:\n');
for i=1:4
for j=1:4
if i~=j
d=d*((z-x(j))/(x(i)-x(j)));
end
sum=sum+d*y(i);
end
fprintf('L%d',i-1);
d
end
disp('Lagrange interpolating polynomial at a given value z is: ')
sum
Get Answers For Free
Most questions answered within 1 hours.