I wrote code for this in Delphi. This time I want to rewrite it in Python based on this wiki.
I use this set of data point
(0,0)
(1,1)
(2,4)
(4,16)
(5,25)
and I use xc=3 for the test data.
It's obvious that these sets of data points have quadratic form and f(xc) must have value of 9.
The heart of code lay on this
Kadang bingung sedang membaca buku @PitoyoAmrih yang mana, saking konsistennya. Banyak cerita yang ada di buku satu, menyisip di buku lainnya. Seakan empat atau lebih buku itu sebenarnya cuma satu buku yang dijilid bukan berdasarkan urutan, namun berdasarkan tema.
Saat membaca "Antareja dan Antasena", tiba-tiba serasa baca "Wisanggeni Membakar Api" saat tiba di bagian Antasena menjadi jagung.
Juga saat membaca "Pertempuran Dua Pemanah: Arjuna-Karna" serasa membaca sisipan dari (atau malah babon) dari "Kebaikan Kurawa".
Apakah itu berarti jelek? Tidak sama sekali. Ini berarti penulis memiliki satu plot besar yang dicurahkan di berbagai buku.
Here's code for Newton's divided differences interpolation polynomial (quite mouthful huh, :) ).
The purpose of this method is to create a function (polynomial) that passes through given set of data points.
Here's my implementation of function according to The Power of 10;
"Restrict functions to a single printed page."
As bonus, I didn't use global variable if possible. So if a function or procedure need a variable from others, it have to be passed using parameter on that function.
If we look at the code below, we know that it can be rewritten using a long single procedure or function. But according The Power of Ten, a function should be as short as possible so it could be printed in a single page.
So, instead one long multiple page function, I write/break it as several short-single-printed-page functions. :)
[TIMON]
Hakuna Matata!
What a wonderful phrase
[PUMBA]
Hakuna Matata!
Ain't no passing craze
[TIMON]
It means no worries
For the rest of your days
[TIMON AND PUMBA]
It's our problem-free philosophy
Hakuna Matata!