If we take the logarithms natural of both sides then this model can be written

# If we take the logarithms natural of both sides then

• 11

This preview shows page 5 - 7 out of 11 pages.

If we take the logarithms (natural) of both sides, then this model can be written ln( W ) = a ln( L ) + ln( k ) , which is a linear relation between the ln( W ) and the ln( L ). There are standard formula to find the Linear Least Squares best fit to linear data. MatLab uses a subroutine polyfit to find the best slope and intercept for a line passing through a data set. ( Note: MatLab uses the natural logarithm in its calculations, so uses the command log(x) to mean ln( x ).) The analysis above shows that the linear least squares fit of a line to the logarithms of the data provides the allometric model. This suggests that MatLab’s polyfit routine can be used to fit these types of models. The following MatLab function allows the easy input of data to produce the parameters for our allometric model: 1 function [ k , a ] = powerfit ( ldata , wdata ) 2 % Power law ( Allometric ) f i t f o r model W = k * Lˆa 3 % Uses l i n e a r l e a s t squares f i t to logarithms of data 4 Y = log ( wdata ) ; % Logarithm of W - data 5 X = log ( ldata ) ; % Logarithm of L - data 6 p = p o l y f i t (X,Y, 1 ) ; % Linear f i t to X and Y with p = [ slope , i n t e r c e p t ] 7 a = p (1) ; % Value of exponent 8 k = exp (p (2) ) ; % Value of leading c o e f f i c i e n t 9 end

Subscribe to view the full document.

Our data file discussed above has the vector data variables ltdfish for length and wtdfish for weight (vectors with 25 elements) of Lake Trout data from the Kory Groetsch data. If we execute our powerfit function with the following MatLab command: 1 [ k , r ] = powerfit ( l t d f i s h , wtdfish ) MatLab outputs the variables k = 0 . 015049 and a = 2 . 8591. It follows that using this method of finding the linear best fit to the logarithms of the data yields a best allometric model of the form: W = 0 . 015049 L 2 . 8591 . From a modeling perspective, this problem can be examined in two other ways. Similar to the section before, a nonlinear least squares best fit can be used to obtain the unbiased best fit of the model (with respect to the parameters k and a ). Alternately, a dimensional analysis supported by the allometric fit above would suggest that the weight of a fish varies like the cube of the length, i.e. , self-similarity of fishes would suggest that as the length increases, then the height and width would similarly increase giving a cubic relation between length and weight. This would fix the parameter a = 3 and only allow changes in k . Below are two functions for finding the sum of square errors for these two models. The function for the 2-parameter problem is 1 function J = sumsq nonlin (p , ldata , wdata ) 2 % Function computing sum of square e r r o r s f o r a l l o m e t r i c model 3 model = p (1) * ldata .ˆ p (2) ; 4 e r r o r = model - wdata ; 5 J = e r r o r * error ’ ; 6 end 7 8 % Obtain the l e a s t sum of square e r r o r s 9 % [ p1 , J , f l a g ] = fminsearch ( @sumsq allom , [ k , a ] , [ ] , l t d f i s h , wtdfish ) ; The MatLab function for the cubic model with only 1-parameter is 1 function J = sumsq cubic (p , ldata , wdata ) 2 % Function computing sum of square e r r o r s f o r cubic a l l o m e t r i c model 3 model = p * ldata . ˆ 3 ; 4 e r r o r = model - wdata ; 5 J = e r r o r * error ’ ; 6 end 7 8 % Obtain the l e a s t sum of square e r r o r s
• Fall '08
• staff

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern