This document contains code to implement Lagrange interpolation to find the value of y at a point x=25 using 5 given data points. The code defines the x and y values of the 5 data points, sets the value of x to interpolate for as 25, initializes the interpolated y value to 0, then uses a double for loop to implement the Lagrange interpolation formula to calculate the interpolated y value by summing the contribution from each data point. It finally displays the interpolated y value.
This document contains code to implement Lagrange interpolation to find the value of y at a point x=25 using 5 given data points. The code defines the x and y values of the 5 data points, sets the value of x to interpolate for as 25, initializes the interpolated y value to 0, then uses a double for loop to implement the Lagrange interpolation formula to calculate the interpolated y value by summing the contribution from each data point. It finally displays the interpolated y value.
This document contains code to implement Lagrange interpolation to find the value of y at a point x=25 using 5 given data points. The code defines the x and y values of the 5 data points, sets the value of x to interpolate for as 25, initializes the interpolated y value to 0, then uses a double for loop to implement the Lagrange interpolation formula to calculate the interpolated y value by summing the contribution from each data point. It finally displays the interpolated y value.
0003 //APP NO : 210810015913 0004 0005 //QUESTION-1(b) LAGRANGE INTERPLOATION 0006 0007 0008 clc; 0009 clear; 0010 n=5 //Total number of data points 0011 0012 //Values of X and Y 0013 x(1)=10; x(2)=20; x(3)=30; x(4)=40; x(5)=50 0014 y(1)=0.1736; y(2)=0.3420; y(3)=0.5000; y(4)=0.6428; y(5)=0.7660 0015 0016 xp=25 //value x of at which y is required 0017 0018 //Implementation of LAGRANGE INTERPOLATION formula 0019 yp=0 0020 for i=1:1:n 0021 a=1 0022 for j=1:1:n 0023 if(j~=i) then 0024 a=a*(xp-x(j))/(x(i)-x(j)) 0025 end 0026 end 0027 yp=yp+a*y(i) 0028 end 0029 disp("value of y at xp is =",yp)