EXPERIMENT NO 9
AIM: To obtain the divided difference and plot the graph of given data and solve the
problem using Lagrange’s Method
SOFTWARE USED: SCILAB 5.0
THEORY:
Divided Difference:
Divided differences is a recursive division process. The method can be used to calculate the
coefficients in the interpolation polynomial in the Newton form. Given k+1 data points
The forward divided differences are defined as:
The backward divided differences are defined as:
Lagrange’s Method
In numerical analysis, Lagrange polynomials are used for polynomial interpolation. For a given
set of points with no two values equal, the Lagrange polynomial is the polynomial of
lowest degree that assumes at each value the corresponding value (i.e. the functions coincide
at each point). The interpolating polynomial of the least degree is unique, however, and since it
can be arrived at through multiple methods, referring to "the Lagrange polynomial" is perhaps not
as correct as referring to "the Lagrange form" of that unique polynomial.
PROBLEM STATEMENT:
To obtain Divided difference for following data:
x 300 304 305 307
y 2.4771 2.4842 2.4841 2.4871
Find value of root of 1.1 using Lagrange’s Method using following table:
X 1 1.2 1.3 1.4
Y 1 1.095 1.14 1.183
PROGRAM :
//Member:Pratima,Somya,Nancy,Abhishek,Harmik,Abhinav
//Date:24-10-18
//
clc
clear
close
//Code for divided difference
z=input("Press 1 for divided difference & 2 for lagrange method :")
if z==1 then
x=input("Enter Elements of x in matrix form :")
y=input("Enter Elements of y in matrix form :")
k=length(y)
d(:,1)=x
d(:,2)=y
n=1
for j=3:k+1
for i=k-1
d(i,j)=(d(i,j-1)-d(i+1,j-1))/(d(i,1)-d(i+n,1))
end
k=k-1
n=n+1
end
disp(d)
Xbar=x(1):0.01:x(4)
for p=1:length(Xbar)
Xr=Xbar(p)
Yr(p)=d(1,2)+(Xr-d(1,1))*d(1,3)+(Xr-d(1,1))*(Xr-d(2,1))*d(1,4)+(Xr-d(2,1))*(Xr-
d(3,1))*d(1,5)
end
plot(Xbar,Yr)
xgrid(2)
xtitle("Graph for divided difference");
xlabel("Xr");
ylabel("Yr");
elseif z==2 then
X=input("Enter Elements of x in matrix form :")
Y=input("Enter Elements of y in matrix form :")
Xr=input("Enter Xr :")
Yr(1)=0
for m=1:length(X)
num=1
den=1
for i=1:length(X)
if i~=m then
num=num*(Xr-X(i))
end
if i~=m then
den=den*(X(m)-X(i))
end
end
Yr(m+1)=Yr(m)+((num/den)*Y(m))
end
disp(Yr(length(X)+1))
end
Output:
Divided difference
Lagrange’s Method
CONCLUSION: Divided difference methods help to accurately plot a curve using given
data.
X