You are on page 1of 1

0001 //End Sem Exam

0002 //NAME: PUSHPENDRA YADAV (025)


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)

You might also like