ABSTRACT

We wish to represent the approximating curve, yc, as a straight line of the form

y c c xc = +1 2 (9.1)

where c1 and c2 are unknown constants to be determined. Let D be the sum of the square of the errors between the approximating line and the actual points. Then,

D y y x y c c xi c i

= − = − + = =

∑ ∑[ ( )] [ ( )]2 1

1 (9.2)

or

D y c c x y c c x y c c xn n= − + + − + + + − +[ ( )] [ ( )] [ ( )]1 1 2 1 2 2 1 2 2 2 1 2 2 (9.3)

To obtain the best-fit straight-line approximating function, minimize D by taking ∂ ∂ = D c1

0 and ∂∂ = D c2

0. Taking the partial derivative of Equation 9.3 with respect to

c1 gives

∂ ∂ = = − + −

∑Dc y c c x i

1 20 2 1[ ( )][ ]

1= − −

∑ ∑y c x nci i

or

nc x c yi

+  

  =

∑ ∑ (9.4) Taking the partial derivative of Equation 9.3 with respect to c2 gives

∂ ∂ = = − + −

∑Dc y c c x xi i i i

0 2[ ( )][ ]

= − −

∑ ∑∑x y c x c xi i i

or

x c x c x yi

∑ ∑ ∑   +

 

  =1 1

1 (9.5)

Equations 9.4 and 9.5 describe a system of two algebraic equations in two unknowns, which can be solved by the method of determinants (Cramer’s rule):

c

y x

x y x

n x

x x

y x x x y

n x

2 = =

( )( ) − ( )( ) ∑ ∑ ∑ ∑

(9.6)

c

n y

x x y

n x

x x

n x y x y

n x x x

2 = =

− ( )( ) − ( )(

(9.7)

9.2.2 Best-Fit mth-Degree Polynomial We can generalize the earlier approach for an mth-degree polynomial fit. In this case, take the approximating curve, yc , to be

y c c x cx c x c xc 2 3 m m= + + + + + +1 2 3 4 1 (9.8)

where m ≤ n − 1 and n is the number of data points. The measured values are (xi, yi) for i = 1, 2, … , n. Let yc,i = yc(xi) be the approximated value of yi at the point (xi , yi). Then,

D y y y c c x cx c xi ci

= − = − + + + +( )  =

(9.9)

To minimize D, take

∂ ∂ =

∂ ∂ =

∂ ∂ =+

D c

D c

0 0 0, , ,…

Then,

∂ ∂ = = − + + +( )  −

∂ ∂ = =

D c

y c c x c x

D c

0 2 1

0 2

[ ]

y c c x c x x

D c

y c c x

− + + +( )  −

∂ ∂ = = − + +

1 20 2

[ ]

+( )  − 

∂ ∂ = = − + + +

c x x

D c

y c c x c x

im imx( )  −  This set of equations reduces to

nc x c x c x c y

x c x c x

+ ( ) + ( ) + + ( ) = ( ) + ( ) +

( ) + + ( ) =

( ) + ( ) + + ( )

c x c x y

x c x c x c

(9.10)

Equation 9.10 can be solved by Gauss elimination (as described in Chapter 4). Alternatively, MATLAB • ’s polyfit function (discussed in Section 9.4) pro-

vides a solution to Equation 9.10, which represents the best-fit polynomial of degree m for the (xi , yi) set of data points.