7
ct
= model ./ wt ;
% c ( t )
8
e r r o r
=
ct

hgdata ;
9
J =
e r r o r
*
error
’ ;
10
end
This program is used in the MatLab script with
fminsearch
to find the best fitting models and
graph the models and the data.
1
mytitle
=
’ Mercury
in
Lake
Trout ’
;
% T i t l e
2
xlab =
’Age
( Years ) ’
;
% X

l a b e l
3
ylab =
’Hg
(ppm) ’
;
% Y

l a b e l
4
5
load
(
’ f i s h d a t ’
) ;
% Provide
vectors
of
Lake
Trout
data
6
7
tt
=
l i n s p a c e
(0 ,20 ,500) ;
% t
domain
of
function
8
9
w1 =
[ 6 2 9 5 . 4 , 0 . 1 4 5 5 3 ] ;
10
[ p1 , J1 ,
f l a g
]= fminsearch (@sumsq
Hg , 0 . 1 , [ ] , tdfish , hgdfish , w1) ;
11
model1 = ( p1
*
w1(1) /(6
*
w1(2) ) )
*
(6
*
w1(2)
*
tt
+ 18
*
exp
(

w1(2)
*
tt )

. . .
12
9
*
exp
(

2
*
w1(2)
*
tt ) + 2
*
exp
(

3
*
w1(2)
*
tt )

11) ;
13
wt1 = w1(1)
*
(1

exp
(

w1(2)
*
tt ) ) . ˆ 3 ;
14
ct1 = model1 ./ wt1 ;
15
w2 =
[ 5 6 7 7 . 6 7 , 0 . 1 6 9 6 0 ] ;
16
[ p2 , J2 ,
f l a g
]= fminsearch (@sumsq
Hg , 0 . 1 , [ ] , tdfish , hgdfish , w2) ;
17
model2 = ( p2
*
w2(1) /(6
*
w2(2) ) )
*
(6
*
w2(2)
*
tt
+ 18
*
exp
(

w2(2)
*
tt )

. . .
18
9
*
exp
(

2
*
w2(2)
*
tt ) + 2
*
exp
(

3
*
w2(2)
*
tt )

11) ;
19
wt2 = w2(1)
*
(1

exp
(

w2(2)
*
tt ) ) . ˆ 3 ;
20
ct2 = model2 ./ wt2 ;
21
22
plot
( tt , ct1 ,
’b

’
,
’ LineWidth ’
, 1 . 5 ) ;
% Plot
model
cubic
von
Bertalanffy
23
hold
on
% Plots
Multiple
graphs
24
plot
( tt , ct2 ,
’ r

’
,
’ LineWidth ’
, 1 . 5 ) ;
% Plot
model
nonlinear
f i t
25
plot
( tdfish , hgdfish ,
’ ro ’
,
’ LineWidth ’
, 1 . 5 ) ;
% Plot
data
with
red
c i r c l e s
26
27
grid
% Adds
Gridlines
28
legend
(
{
’ Cubic
von
Bertalanffy ’
,
’ Nonlinear
Fit ’
,
’ Data ’
}
,
’ l o c a t i o n ’
,
’ Northwest ’
,
’
FontSize ’
,10 ,
’FontName ’
,
’ Times New Roman ’
) ;
% Create
legend
29
xlim ( [ 0
2 0 ] ) ;
% Defines
l i m i t s
of
graph
30
ylim ( [ 0
0 . 7 ] ) ;
This MatLab script finds that using the weight model with the cubic best fitting von Bertalanffy
model gives
κ
= 0
.
071406 with a least sum of square errors to the data of
J
= 0
.
17113, while the
weight model with the cubic nonlinear fit model gives
κ
= 0
.
066953 with a least sum of square
errors to the data of
J
= 0
.
17427. The graph is shown below with the data, and it is clear that
choice of model is almost indistinguishable between these two models compared to the data.