From 663b5b5185f31ea158cbee0aeb8974b260d73e4b Mon Sep 17 00:00:00 2001 From: VaishnavaHari S <cb.en.u4mee16159@cb.students.amrita.edu> Date: Thu, 11 Oct 2018 14:45:30 +0530 Subject: [PATCH] Add new file --- lagrange_interpolation.m | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lagrange_interpolation.m diff --git a/lagrange_interpolation.m b/lagrange_interpolation.m new file mode 100644 index 0000000..5767870 --- /dev/null +++ b/lagrange_interpolation.m @@ -0,0 +1,40 @@ +%Lagrange's interpolation +%clear all +% Interpolating data by Lagrange's method +%input + + +function yp = LAGRANGE_S(n, x, y, xp) +%main program + L = zeros(n); + for i =1:n + L(i)=1; + for j =1:n + if (i~=j) + L(i)= L(i)*(xp-x(j))/(x(i)-x(j)); + end + end + end + yp=y*L'; + %ouput + %fprintf('the required value of y at xp is %f',yp) + + % Note: To see the data with multipliers use the follwoing 2 liines + %fprintf('x y L y.*L\n') + table = [x;y;L; y.*L]'; + +%--------------------------------------------------------------------- +% OUTPUT 1 +% enter the no. of data points = 5 +% enter the x values as a row matrix [1 2 3 4 5] +% enter the y values as a row matrix [2 4 10 15 20] +% enter the x value for which y is to be evaluated = 1.5 +% the required value of y at xp is 1.953125>> + +%--------------------------------------------------------------------- +% OUTPUT 1 +% enter the no. of data points = 5 +% enter the x values as a row matrix [1 2 3 4 5] +% enter the y values as a row matrix [2 4 10 15 20] +% enter the x value for which y is to be evaluated = 3.5 +% the required value of y at xp is 12.703125>> \ No newline at end of file -- GitLab