Professional Documents
Culture Documents
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
Find value of root of 1.1 using Lagrange’s Method using following table:
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