function J = sumsq_Hg(p,tdata,hgdata,w)
% Function computing sum of square errors for von Bertalanffy model
% p is kappa, tdata and hgdata are fish data, w = [W*,b]
model = (p*w(1)/(6*w(2)))*(6*w(2)*tdata + 18*exp(-w(2)*tdata) - ...
    9*exp(-2*w(2)*tdata) + 2*exp(-3*w(2)*tdata)-11);  % H(t)
wt = w(1)*(1 - exp(-w(2)*tdata)).^3;                  % W(t)
ct = model./wt;                                       % c(t)
error = ct - hgdata;
J = error*error';
end

% Obtain the least sum of square errors
% w1 = [6295.4,0.14553];
% [p1,J,flag]=fminsearch(@sumsq_Hg,0.1,[],tdfish,hgdfish,w1);
