
clear				% Clear previous definitions
figure(1)           % Assign figure number
clf                 % Clear previous figures
hold off            % Start with fresh graph

mytitle = 'Mercury in Lake Trout'; 	% Title
xlab = 'Age (Years)'; 		        % X-label
ylab = 'Hg (ppm)'; 	         	% Y-label

load('fishdat');         % Provide vectors of Lake Trout data

tt = linspace(0,20,500);	% t domain of function

w1 = [6295.4,0.14553];
[p1,J1,flag]=fminsearch(@sumsq_Hg,0.1,[],tdfish,hgdfish,w1);
model1 = (p1*w1(1)/(6*w1(2)))*(6*w1(2)*tt + 18*exp(-w1(2)*tt) - ...
    9*exp(-2*w1(2)*tt) + 2*exp(-3*w1(2)*tt)-11);
wt1 = w1(1)*(1 - exp(-w1(2)*tt)).^3;
ct1 = model1./wt1;
w2 = [5677.67,0.16960];
[p2,J2,flag]=fminsearch(@sumsq_Hg,0.1,[],tdfish,hgdfish,w2);
model2 = (p2*w2(1)/(6*w2(2)))*(6*w2(2)*tt + 18*exp(-w2(2)*tt) - ...
    9*exp(-2*w2(2)*tt) + 2*exp(-3*w2(2)*tt)-11);
wt2 = w2(1)*(1 - exp(-w2(2)*tt)).^3;
ct2 = model2./wt2;

plot(tt,ct1,'b-','LineWidth',1.5);  % Plot model cubic von Bertalanffy
hold on                            % Plots Multiple graphs
plot(tt,ct2,'r-','LineWidth',1.5);  % Plot model nonlinear fit
plot(tdfish,hgdfish,'ro','LineWidth',1.5);  % Plot data with red circles

grid                                % Adds Gridlines
legend({'Cubic von Bertalanffy','Nonlinear Fit','Data'},'location','Northwest', 'FontSize',10,'FontName','Times New Roman');  % Create legend
xlim([0 20]);  % Defines limits of graph
ylim([0 0.7]);

fontlabs = 'Times New Roman';   % Font type used in labels
xlabel(xlab,'FontSize',14,'FontName',fontlabs,'interpreter','latex');  
        % x-Label size and font
ylabel(ylab,'FontSize',14,'FontName',fontlabs,'interpreter','latex');  
        % y-Label size and font
title(mytitle,'FontSize',16,'FontName','Times New Roman','interpreter','latex'); 
        % Title size/font
set(gca,'FontSize',12);         % Axis tick font size

print -depsc Hgfish.eps		% Create figure as EPS file
%print -djpeg Hgfish.jpg		% Create figure as JPEG file

