0 ratings0% found this document useful (0 votes) 52 views3 pagesInterpolation Newton Python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
This notebook contains on excerpt from the Bthon Prasramming and Nurrical Methods -A Guide for
Engineers ond Scientists, the conten i aso availabe ot Berkeley Python Numerical Methods
The copyright ofthe book belong to Elsevier. We also have this interactive bok online fora better
learning experience. The cde is released under the 4 license I you find his content useful pease
consider supporting the work on Elsevier or Amazon!
< 174Lasrange Polynomial Interpolation | Contents | 17.6 Summary and Problems >
Newton’s Polynomial Interpolation
‘Newton's polynomial interpolations another popular way tft exactly fra set of datapoints. The general form of
the ann — 1 order Newton's polynomial that goes through n points:
sa)
aq + 1 (2 ~ 29) + an(2 — z0)( ~ 21) +20 + ag 2 — 20)(2— 21)... (2-29)
which canbe re-written a:
fle) = Yanile)
where $n (e) = []5(2 — 2))8
“Te special feature ofthe Newton's polynomials thatthe coetcents a, canbe determined using avery simple
‘mathematical procedure. For example, since the polynomial goes through each datapoints, therefore, fora data
points (2, ys) we willhave f(a) — yarthus we have
f(e) = a9 = v0
‘And fe.) = ay + ay (1 ~ sy) = ys. by rearranging ito get ay, we will have
_ mow
Now insert datapoints (2, y2),wecan calculate a, andit isin the form:
=
Lets do one more data points (xs, ys) to calculate as, after insert the data point nto the equation, we et
fe, tol =
fiz2,21,20] =e >
‘We continue write this out, we will have the following iteration equation:
on 92) ~ flee tias---s2n.20)
Slee thay 21,20) =
‘We can see one beauty ofthe method is that, once the coefficients are determined, adding new datapoints won't
‘change the calculated ones, we onlyneed to calculate higher ifferences continues inthe same manner. The whole
procedure for finding these coefficients can be summarizedintoadlvded differences table Le's see an examplesing 5 datapoints
2 vo
flr, 20]
ah ‘Flea, 21,0)
Siea,21] fla, 32,21,20)
ah Sls, 22,21] flea, 2s,22, 21,20]
Flas, 22] Fle4) 25,2271)
zy vs ‘flx4, 2,22)
Shes, 2s]
aM
ach elementin the table can be caleulated using the two previous elements (tothe lft). In eality, we can calculate
‘each element and store them intoadiagonal matrix, that isthe coefficlents matrixcan be write as
yo Sere] flzez1,z0) fles.22,21,20) flee2s, 32,21, 20)
my flea) flea z2,21) fles,29, 22,21] °
ve fles,za] flea, 23,22] 0 0
vs flze,za) 0 o 0
woo o 0 °
Note that, the first rowin the matrix is actually athe coefficients that we need, Le. ay, 01,2, a5, 4. Let's see an
‘example how we can doit
‘TRY IT! Calculate the cvided difterences table for
Amport unpy 28 np
Amport atplotlsb:pyplot as pit
ple.style.uset'seaborn-poster")
sastplotiib inline
(ef divided siF#(x, y):
‘function to catcutote the divided
efferences tob.e
n= lenly)
Coet = np-2er056(n, 0)
te first column {2 9
coef.) = ¥
for 9 an rangetssn)
for t in rangetoe3):
coeff] = \
(easel sAi(-2) ~ eoeeteis-ab / (o6t45)-x00)
et neon poly (coer, %0ata, #)
= lenge data) =
B= coefla)
for fein range(3y 162):
> coatfnek} = (& -~6ataln-k])"p
return
= 9,21)
4,"
4 get the siviaes disference coef
2S = alvides diet(s, y910, 2]
1 evoluate on new dato potnts
now = maarangetesy 2) 3)
Yano = newton poly(@.s, 2s XPM)
plt.tigura(figsize = (22, 8))
ple-pleece, y, "80")
Plt-plotOx news y-nem)[cnatplotit. Lines. .ineaD at @xit6dte639>]
u
2
10
“4
0
We cance thatthe Newton's polynomial oes through al the datapoints and ft the data
+ 17.4 Lagrange Polynomial Interpolation | Contents | 17.6 Summary and Problems >
‘©Copyright 2020.
You might also like
X X F (X F ' (X, N 0,1,2, - ..: Algorithm:Set X (X +X) /2, If F (X) F (X) 0 Then X X - Otherwise, X x3
X X F (X F ' (X, N 0,1,2, - ..: Algorithm:Set X (X +X) /2, If F (X) F (X) 0 Then X X - Otherwise, X x3
13 pages