next up previous
Next: Example 3 Up: Least Square Lines Previous: Least Square Lines

Example 2

Find the equation y=mx + c of the least square line that best fits the data from example 1:

tex2html_wrap_inline169

This line is called least-squares line and the coefficients m and c are called regression coefficients.

Solution :

First form your matrix A, then solve the linear system tex2html_wrap_inline273.

i) Enter the data matrix D as:

D=[5/2 3 3/2 1; 1 1 1 1 ; 2 9/2 2 1 ]'

Note that A = D(:,[1 2]) and b= D(:,3)

ii) Find the augmented matrix of the system tex2html_wrap_inline273 by typing

AG= [ ( D(:,[1 2]) )' *( D(:,[1 2]) ) ( D(:,[1 2]) )'*( D(:,3) ) ]

Then find the rref of the agumented matrix by typing

RAG=rref(AG)

This should give you m= -7/5 and c= 17/40 .