next up previous
Next: Exercise Up: Least Square Lines Previous: Example 2

Example 3

The method used to fit a straight line to data pointsin example 1 can be easily generalized to a polynomial of a given degree.

find equation of a polynomial of degree 3, tex2html_wrap_inline393 that best fits the following data.

tex2html_wrap_inline395

Solution :

Note that we want to find the coefficients of a third degree polynomial tex2html_wrap_inline397

Therefore the linear system Ax=b would be

tex2html_wrap_inline401

To form your matrix A first enter the data in MATLAB as

D3=[ 2 1 0 -2 5 -1 ; 1 1 1 1 1 1 ; 7 -2 -7 -27 110 -20 ]'

Enter your coefficient matrix A3

tex2html_wrap_inline405

Enter your matrix b as

b3= D(:,3)

Solve the linear system tex2html_wrap_inline409.

To find the augmented matrix type

AG3= [ (A3)'*(A3) (A3)'*b3 ]

Then find the rref of the augmented matrix by typing

RAG3=rref(AG3)

This should give you tex2html_wrap_inline411.