Curvefitting PDF
Curvefitting PDF
height of Oxygen in
dropped soil
object
time temperature
pore Profit
pressure
How can we pick the coefficients that best fits the line to the data?
Why does the blue line appear to us to fit the trend better?
• Consider the distance between the data and points on the line
• Add up the length of all the red and blue verticle lines
• The one line that provides a minimum error is then the ‘best’
straight line
$ $ $
%&& " ∑ ( '( ) " ( )% & ! ( "% ) ) # ( )$ & ! ( "$ ) )
$ $
''''''''''''''''''''''''''' # ( ) ( & ! ( " ( ) ) # ( ) ) & ! ( " ) ) )
*'+,-,'./01-2 *'+,-,'./01-2
$ $
%&& " ∑ ( ) ( & ! ( "( ) ) " ∑ ( ) ( & ( #" ( # $ ) )
("% ("%
The ‘best’ line has minimum error between line and data points
This is called the least squares approach, since we minimize the square of the error.
*'+,-,'./01-2'"'*
$
minimize %&& " ∑ ( ) ( & ( #" ( # $ ) )
("%
*
∂%&&
----------- " & $
∂# ∑ " ( ( ) ( & #" ( & $ ) " !
("%
*
∂%&&
----------- " & $
∂$ ∑ ( ) ( & #" ( & $ ) " !
("%
Solve for the # and $ so that the previous two equations both = 0
re-write these two equations
$
# ∑ "( # $ ∑ "( " ∑ ( "( )( )
# ∑ " ( # $3* " ∑ )(
put these into matrix form
* ∑ "(
$ " ∑ )(
$ #
∑ "( ∑ "( ∑ ( "( )( )
what’s unknown?
we have the data points ( " , ) ) for ( " %, 4445'* , so we have all the summation terms in the matrix
( (
* ∑ "( ∑ )(
+ " , , " $ , - "
$
∑ "( ∑ "( # ∑ ( "( )( )
so
+, " -
using built in Mathcad matrix inversion, the coefficients # and $ are solved
>> X = A-1*B
i 1 2 3 4 5 6
6 748 $ " $!498:( , $ " (*. 6 748 3 $!498:( , $ " & !4:78
748 %(478 # )%4689) # 748 %(478 )%4689) # (486%
Profit
Example #1:
i 1 2 3 4 5 6
$
* ∑ "( ∑ "( #! ∑ )(
∑ "( ∑ "( ∑ "(
$ ( # "
% ∑ "( )(
$
$ ( ) #$ ∑ "( )(
∑ "( ∑ "( ∑ (
"
Now plug in the given data.
Before we go on...what answers do you expect for the coefficients after looking at the data?
* " 6
∑ "( " 748 , ∑ )( " %(478
$
∑ "( " %(478 , ∑ "( )( " $94%$8
( $
∑ "( " $94%$8 ∑ "( )( " 6%4%978
)
∑ "( " 6%4%978
#!
6 748 %(478 %(478
748 %(478 $94%$8 # % " $94%$8
%(478 $94%$8 6%4%978 # 6%4%978
$
$ $
Note: we are using ∑ "( , NOT ( ∑ " ( ) . There’s a big difference
#!
6 748 %(478 %(478
using the inversion method # " (*. 748 %(478 $94%$8 3 $94%$8
%
#$ %(478 $94%$8 6%4%978 6%4%987
#!
! $
#% " ! ===> ! ( " ) " ! # !3" # %3"
#$ %
This fits the data exactly. That is, f(x) = y since y = x^2
x = [0 .0 1 1.5 2 2.5]
y = [0.0674 -0.9156 1.6253 3.0377 3.3535 7.9409]
The resulting system to solve is:
#!
6 748 %(478 %84%!:(
# % " (*. 748 %(478 $94%$8 3 ($4$9()
#$ %(478 $94%$8 6%4%978 7%4$76
#!
& !4%9%$
giving: #% " & !4($$%
#$ %4(8(7
$
! ( " ) " & !4%9%$ & !4($$%"3 # %4(8(73"