forked from gisalgs/geom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneville.py
34 lines (29 loc) · 815 Bytes
/
neville.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
"""
A Python program for the Neville's algorithm.
Contact:
Ningchuan Xiao
The Ohio State University
Columbus, OH
"""
__author__ = "Ningchuan Xiao <[email protected]>"
def neville(datax, datay, x):
"""
Finds an interpolated value using Neville's algorithm.
Input
datax: input x's in a list of size n
datay: input y's in a list of size n
x: the x value used for interpolation
Output
p[0]: the polynomial of degree n
"""
n = len(datax)
p = n*[0]
for k in range(n):
for i in range(n-k):
if k == 0:
p[i] = datay[i]
else:
p[i] = ((x-datax[i+k])*p[i]+ \
(datax[i]-x)*p[i+1])/ \
(datax[i]-datax[i+k])
return p[0]