fitting logistic growth equation to data

17 vues (au cours des 30 derniers jours)
LS
LS le 14 Juil 2011
Hi all,
I'm trying to fit the logistic growth equation to a set of algae growth data I have to calculate the growth rate, r. The data that I'm trying to fit to the equation is cell counts per mL every day for about 20 days. I have some code so far (below) but it isn't working/isn't complete (right now I'm getting some errors which I've copied below all the code) . 'logistic' is the separate script that holds the logistic growth equation, and I've copied that script below the main script. I want to get the best estimate of r using a least-squares technique. Any help would be very much appreciated! Thanks very much!
% Data import
load 'cultures1e3.csv' %load data for culture
global dataT dataN1
dataT = cultures1e3(:,1); %x = time (days)
dataN1 = cultures1e3(:,2); %y = cell count (cells/mL)
%%Curve fitting
% Initial estimates for r
r0 = 0.1;
% Estimate parameters
%fh = @logistic;% Function handle - started with this but eventually went with str2func
fh = str2func('logistic');
tic
pFit = lsqcurvefit(fh , r0, dataT, dataN1) ;
toc
-----logistic() script ----- function logistic() %logistic growth equation for data fitting
global dataT
funcN_init = 1e3;
K = 3.5e6; %estimate of carrying capacity
r = .1; %growth rate --> what I want to estimate
%options
options = [];
% Solver
[dataT funcN] = ode45(@odefun, dataT, funcN_init, options, r, K);
function f_prime = odefun(dataT, funcN, r, K)
f_prime = r * funcN * (1 - funcN / K);
end
Errors I'm getting:
??? Error using ==> logistic
Too many input arguments.
Error in ==> lsqcurvefit at 209
initVals.F =
feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in ==> logistic_growth_data_fit at 22
pFit = lsqcurvefit('logistic' , r0, dataT, dataN1) ;
Caused by:
Failure in initial user-supplied objective
function evaluation. LSQCURVEFIT cannot
continue.

Réponses (1)

Walter Roberson
Walter Roberson le 14 Juil 2011
Read the documentation . The function you supply (logistic) must take two parameters, but the function you defined takes no parameters. Even if you ignore the parameters for some reason, your function still has to expect them to be passed.
  1 commentaire
LS
LS le 14 Juil 2011
Thanks very much for your help! I've read the documentation (along with a lot of other resources) but I find a lot of what's written hard to understand by someone relatively new to Matlab. Where do you mean the function that I defined takes no parameters? Do you mean I should add variables in the pfit term, maybe something like this:
pFit = lsqcurvefit(fh , r0, dataT, dataN1, r, K) ;
Thanks again for your help!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by