Experiment 3 Interpolation of Data , Polynomial Functions ( Lagrange Interpolation )

Interpolation of Data, Polynomial Functions ( Lagrange Interpolation )

CONCEPT:- 

(a)  (Function Fit) Suppose the given data set contains n + 1 elements (xi , yi). The idea is to look for a linear combination of exactly n + 1 set of functions fk(x) = x k for all k = 0 to n that can best describe the given data. In nutshell, for all i = [0, n] 

                                             yi = X(n, k=0 )αk(xi)^k   (where X is sigma and limits k=0 to n)

where coefficients αk decides the unique linear combination is required. 

(b)  (Interpolation) 
Now for any arbitrary x, the estimate y can be obtained by the relation 
                                             
                                                               y(x) = X(n,k=0) αkx^k 


METHOD/CODE:- 

(a)  (Lagrange Interpolation Basis Function)
                                  Given an n + 1 data set (xi , yi) for i = 0, ..., n; the basis set of functions Li(x)∀ i = 0 to n is found to be 

                Li(x) = Y(n,k=0) (k~=i) (x − xk)/(xi − xk)  where Y is submission Pi(and li. 0 to n and k is not eual to i)

and the interpolating polynomial is
 
                                                Pn(x) = y0L0(x) + y1L1(x) + ... + ynLn(x) 


(b) (Inverse Lagrange Interpolation)
                                
                    Given an n + 1 data set (xi , yi) for i = 0, ..., n; the basis set of functions Li(y)∀ i = 0 to n is found to be   

                                              Li(y) = Y(n,k=0)(k~=i) (y − yk)/(yi − yk)  

where Y is submission Pi(and li. 0 to n and k is not eual to i)
and the interpolating polynomial is 

                                             Qn(y) = x0L0(y) + x1L1(y) + ... + xnLn(y)


APPLICATION:-

(a)  (Bessel Function) 

Consider a set of data for the Bessel function

 J0(β): β 0.00 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 
J0(β) 1.0 0.99 0.96 0.91 0.85 0.76 0.67 0.57 0.46 0.34 0.22 0.11 0.00 -0.10 -0.18 -0.26 

Find out the value of the Bessel function at β = 2.3. Also find out the value of β for which the Bessel function J0(β) = 0.5 .


SCILAB CODE FOR THE GIVEN PROBLEM :-

clc
clf
//Interpolation of Data Polynomial Functions ( Lagrange Interpolation )
X = [0.00,0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8 , 2.0, 2.2, 2.4, 2.6, 2.8, 3.0 ];
Y = [1.0, 0.99, 0.96, 0.91, 0.85, 0.76, 0.67, 0.57, 0.46, 0.34, 0.22, 0.11, 0.00, -0.10,-0.18, -0.26 ];
plot(X,Y,".r")
n= length(X) - 1;
k=0;
x= 2.3;
for i = 1:n+1
L = 1
for j = 1 : n+1
if j ~= i
L= L* ((x- X(j))/(X(i) - X(j)) );
end
end
k= k + Y(i) * L;
end
disp(k,"value of bassel function at 2.3 is:" )
w=linspace(-0.02,3.02,100)
ya=0;
function ya=ip(w)
for i = 1:n+1
L = 1
for j = 1 : n+1
if j ~= i
L= L* ((w- X(j))/(X(i) - X(j)) );
end
end
ya=ya+Y(i) * L;
end
endfunction
plot(w,ip,"b");
plot(X,Y,'r-.o');
plot(x,k,'g*')
xtitle("Lagrange Interpolation","x","J0(x)");
xstring(0.4,-0.1,"Y: "+string(k));
legend("Interpolating Polynomial","Data");
// Inverse lagrange interpolation
d=0;
y= 0.5;
for i = 1:n+1
W= 1;
for j = 1:n+1
if i ~=j
W = W* ( (y - Y(j))/ (Y(i) - Y(j) ))
end
end
d = d + X(i)* W;
end
disp(d, "the value of beta at the bessel funtion is 0.5:")
plot2d(d,y,-1)
xstring(0.4,-0.2,"d: "+string(d))
xgrid(6,1,7)
xs2png(0,'Interpolation')
/value of bassel function at 2.3 is:
//0.0550338
//the value of beta at the bessel funtion is 0.5:
// 1.5373769



//University of Delhi //Department of Physics
if You have any Problem or query, Please comment Or Reach us out at scilabprogram@gmail.com,



Comments

Popular posts from this blog

Experiment 4:- Simultaneous Equations Matrix Method ( Gauss-Jordan Gauss Siedel Method )

Experiment 1 Data Fitting, Method of Least Squares ( Linear Regression )

Experiment 7 Differential Equation First Order ( Euler Method )