0% found this document useful (0 votes)
5 views3 pages

Mahalakshmi R Interpolation Assignment

Uploaded by

rmaha1908
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Mahalakshmi R Interpolation Assignment

Uploaded by

rmaha1908
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Code:

print ("Mahalakshmi R")


print ("21st October")
print("")
print("Forward Interpolation")

def u_cal(u,n):
temp=u;
for i in range (1,n):
t0=temp;
temp=temp* (u-i);
print ("Present Iterations: {} ({}-{})={}".format(t0,u,i,temp))
return temp;

x=[1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8];


value=2.5;
u= ((value-x[0]) / (x[1]-x[0]))
print("u= ({}-{})/({}-{})".format(value, x[0],x[1],x[0]))
print(u_cal(u,len(x)))
print ("n= ",len(x))
print ("")
print("Backward Interpolation")

def u_cal(u,m):
temp=u;
for i in range (1,m):
t0=temp;
temp=temp* (u+i);
print ("Present Iterations: {} ({}-{})={}".format(t0,u,i,temp))
return temp;

m=9
x=[1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8];
value=2.5;
u= ((value - x[m-1]) / (x[1]-x[0]))
print("u= ({}-{})/({}-{})".format(value, x[0],x[1],x[0]))
print(u_cal(u,len(x)))
print ("m= ",len(x))

Output:
Mahalakshmi R
21st October

Forward Interpolation
u= (2.5-1.2)/(1.4-1.2)
Present Iterations: 6.500000000000002 (6.500000000000002-
1)=35.75000000000002
35.75000000000002
n= 9

Backward Interpolation
u= (2.5-1.2)/(1.4-1.2)
Present Iterations: -1.4999999999999993 (-1.4999999999999993-
1)=0.7499999999999987
Present Iterations: 0.7499999999999987 (-1.4999999999999993-
2)=0.37499999999999983
Present Iterations: 0.37499999999999983 (-1.4999999999999993-
3)=0.5625
Present Iterations: 0.5625 (-1.4999999999999993-
4)=1.4062500000000004
Present Iterations: 1.4062500000000004 (-1.4999999999999993-
5)=4.921875000000003
Present Iterations: 4.921875000000003 (-1.4999999999999993-
6)=22.148437500000018
Present Iterations: 22.148437500000018 (-1.4999999999999993-
7)=121.81640625000011
Present Iterations: 121.81640625000011 (-1.4999999999999993-
8)=791.8066406250008
791.8066406250008
m= 9

You might also like