1. ## Pn(x) Polynomial fitting

Hello, out there! I am Samuel.

Please, I need your assistance to fit the following set of data points with a polynomial (could be Newtons divided difference polynomial):

 i 0 1 2 3 4 5 6 7 8 9 1 11 xi 0.005 0.01 0.02 0.03 0.05 0.1 0.2 0.3 0.4 0.6 0.8 1 f(xi) 0.376 0.41 0.428 0.486 0.537 0.624 0.556 0.512 0.45 0.378 0.274 0.106

I need the polynomial to pass through all the data points.

Looking forward to your kind response.

Thanks.

2. ## Re: Pn(x) Polynomial fitting

Here. I'll create a polynomial that passes through for your first three points

.005 f(.005) = .376
.01 f(.01) .41
.02 f(.02) = .428

Since we have 3 points, assume that there exists a polynomial $\displaystyle p(x) = a_2 x^2 + a_1 x + a_0$ such that $\displaystyle p(x_i) = f(x_i)$. Then
p(.005) = $\displaystyle a_2 (.005)^2 + a_1 (.005) + a_0 = .376$
p(.01) = $\displaystyle a_2 (.01)^2 + a_1 (.01) + a_0 = .41$
p(.02) = $\displaystyle a_2 (.02)^2 + a_1 (.02) + a_0 = .428$

What we get is a system of linear equations with 3 unknowns and 3 equations.
$\displaystyle \begin{bmatrix} (.005)^2 & (.005) & 1\\ (.01)^2 & (.01) & 1 \\ (.02)^2 & (.02) & 1 \end{bmatrix} \begin{bmatrix} a_2 \\ a_1 \\ a_0 \end{bmatrix} = \begin{bmatrix} .376 \\ .41 \\ .428 \end{bmatrix}$

So solving, i get $\displaystyle a_2 = -333.33$ $\displaystyle a_1 = 11.8$ and $\displaystyle a_0 = .325$ .

So our polynomial is $\displaystyle p(x) = -333.33x^2 + 11.8x + .325$

So verification
$\displaystyle p(.005) = -333.33(.005)^2 + 11.8(.005) + .325 = .376$
$\displaystyle p(.01) = -333.33(.01)^2 + 11.8(.01) + .325 = .41$
$\displaystyle p(.02) = -333.33(.02)^2 + 11.8(.02) + .325 = .428$

So There ya go. Just do this for all your data points and use this linear solver linked below to get the coefficients.
Linear solver

The linear solver seems to be able to only solve 9 linear equations in 9 variables. So i got for the first 9 points
$\displaystyle -400000000.0x^8 + 438999999.99999994x^7 + -180000000.0x^6 + 34700000.0x^5 + -3319243.63x^4 + 156177.88x^3 + -3498.67x^2 + 37.53x^1 + 0.26x^0 +$

Here are the test results
Got Value $\displaystyle p(x_i): 0.38$ Expected Value $\displaystyle f(x_i): 0.376$
Got Value $\displaystyle p(x_i): 0.41$ Expected Value $\displaystyle f(x_i): 0.41$
Got Value $\displaystyle p(x_i): 0.43$ Expected Value $\displaystyle f(x_i): 0.428$
Got Value $\displaystyle p(x_i): 0.49$ Expected Value $\displaystyle f(x_i): 0.486$
Got Value $\displaystyle p(x_i): 0.53$ Expected Value $\displaystyle f(x_i): 0.537$
Got Value $\displaystyle p(x_i): 0.18$ Expected Value $\displaystyle f(x_i): 0.624$
Got Value $\displaystyle p(x_i): -14.35$ Expected Value $\displaystyle f(x_i): 0.556$
Got Value $\displaystyle p(x_i): -106.13$ Expected Value $\displaystyle f(x_i): 0.512$
Got Value $\displaystyle p(x_i): -360.17$ Expected Value $\displaystyle f(x_i): 0.450$

As you can see every data point added makes the polynomial error grow at a very large rate, i guess that is to be expected