forked from sweety665/important
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
34 lines (26 loc) · 741 Bytes
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
n= int(input("Enter the number of data points: "))
x= np.zeros(n)
y= np.zeros((n,n))
print("Enter data for x and y: ")
for i in range(n):
x[i]= float(input('x['+ str(i)+']='))
y[i][0]= float(input('y['+str(i)+']='))
a= float(input("Enter the vlaue at which you want to interpolate: "))
h= x[1]-x[0]
u= (a-x[n-1])/h
ans= y[n-1][0]
p=1
for i in range(1,n):
for j in range(n-1,i-2,-1):
y[j][i]= y[j][i-1]- y[j-1][i-1]
print('\n Backward Difference Table\n')
for i in range(0,n):
print((x[i]),end='')
for j in range(0,i+1):
print('\t\t', (y[i][j]),end='')
print()
for m in range(1,n):
p= p* (u+m-1)/m
ans= ans+ p*y[n-1][m]
print("Value of the function at ",a," is ",ans)