Friday, August 4, 2023

An Introduction To Numerical Analysis (6): Fitting A Polynomial To A Set of Data Points

 We are tasked in this form of  quantitative approximation with fitting a polynomial of form x 2 +  bx  + c  to a set of points,   (x1 , y1 ,  x2 , y2  , x3 , y3   ,  x4 , y4 )say as displayed in a  table:

To proceed we use functional form and choose a, b, c to minimize the functional, so that:

F(a,b,c) =  å 4 =1  (axi  2 +  bxi    c   -  yi)  2 


This can be done by solving the linear system of equations:

  f/a = 0,        f/b = 0,  f/c = 0

Example problem:  Fit a second degree polynomial  to the ordered pairs in the table below:


Solution: Compute using functionals below by inserting respective values for  (xi,  yi):

f/a =  2 (axi  2 +  bxi    c   -yi)xi 2  = 0

Then:

(-2,1): 32a -  16b + 8c - 8 = 0

(-1, 1): 2a    - 2b   +2c + 2 = 0

(0, 2):   0

(1, 1): 2a  + 2b + 2c - 2  = 0

            ------------------------

Summing: 36a - 16b +12c - 8 = 0

f/b  2 (axi  2 +  bxi    c   -yi)xi   = 0

(-2,1 ): - 16a + 8b - 4c + 4 = 0

(-1, -1):  -2a  - 2b - 2c -2  = 0

(0, 2):      0

(1, 1):     2a  + 2b  + 2c  - 2 = 0

---------------------------------

     Sum:   16a + 12b  - 4c = 0


f/c =  2 (axi  2 +  bxi    c   -yi)   = 0

(-2, 1):  8a - 4b + 2c - 2 = 0

(-1, -1): 2a - 2b + 2c + 2 = 0

(0, 2): 2c - 4 = 0

(1, 1): 2a -4b + 8c - 6 = 0

 -----------------------------

Sum:  12a - 4b + 8c - 6 = 0

From the 3 sums we arrive at a 3 x 3 system given by:

36a - 16b +12c - 8 = 0

16a + 12b  - 4c = 0

12a - 4b + 8c - 6 = 0

Or, written in matrix form:


The values for a, b, c can then either be found using Gaussian elimination with pivotal condensation or matrix inversion. We choose the latter as it is more straightforward and amenable to a good computing program.

Using this method and Mathcad we obtain:


The unknowns a, b and c can also be computed using the Gaussian elimination calculator below. 


Simply insert the original array values for M and the values for v - and see all the steps that would normally be needed and the solutions for a, b and c.

The calculator will also perform a check of your result.

Suggested Problem:

 Fit a second degree polynomial  to the ordered pairs in the table below:


Hence, find a, b and c for the polynomial: axi 2 +  bxi    c 


No comments: