Of few words.
Nowton interpolation polynomials (non-equidistant nodes) Code:
. 1 # - * - Coding: UTF-. 8 - * -
2 "" "
. 3 the Created-Mar Wed 25 15:43:42 2020 ON
. 4
. 5 @author: 35035
. 6 " ""
. 7
. 8
. 9 Import numpy NP AS
10
. 11 # the Newton interpolation polynomial
12 is DEF Newton_iplt (X, Y, XI):
13 is "" " X, Y are interpolation nodes array, xi is a value of " ""
14
15 n-= len (X)
16 m = len (Y)
. 17 IF n- ! = m:
18 is Print ( ' Error! ')
. 19 return None
20 is # calculated first difference quotient table (CS)
21 is CS = []
22 is TEMP = y.copy ()
23 is for I in Range (n-):
24 for J in Range (I, n-):
25 IF I! = 0:
26 is TEMP [J] = (TEMP [J] - TEMP [J -. 1]) / (X [J] - X [J - I])
27 cs.append (TEMP [I])
28 # recalculation Newton interpolation
29 ANS = 0
30 for I in Range (n-):
31 is W =. 1
32 # evaluator polynomial portion, so that difference quotient table as coefficients
33 is for J in Range (I):
34 is W * = (XI - X [J])
35 ANS + = W * CS [I]
36 return ANS
37 [
38 is # when a plurality of values using Lagrange interpolation, using the map () establishes a mapping:
39 # the Iterator = Map (Lagrange, the Iterable)
40
41 is # use float value calculation involved in computing, as a built-DTYPE float
42 is X = NP .Array ((100, 121), DTYPE = a float)
43 is Y = np.array ((10,. 11), DTYPE = a float)
44 is Print (Newton_iplt (X, Y, 115))
45 # test successfully!
在Nowton插值多项式中,差商表的计算至关重要,而对于等距节点的Newton插值,则转为计算差分表。