odearguments error for fitting data with system of ODEs
Mostrar comentarios más antiguos
Hi all,
I have some experimental data (attached) that I need to fit with the following model.
I want to fit the data with M(t), but I need to solve the whole system (obviously). Additionally, there are four parameters that I need to extract from the fit once I am done (
). I've tried to follow a number of previous posts to write the code:
This is what I have so far, but it's giving me the error below. I plan on plotting the curve resulting from the fit values y (I really only want y(2), or M(t)) and reporting the parameter p values, and I'm not even sure I'll be able to extract all of those results from this script.
Thanks for any help you can give! Let me know if you would like any more information to help figure this out.
p = lsqcurvefit(@MSolve,pguess,t,f);
% t = time
% f = raw data
function y = MSolve(p,t)
cond1 = 0;
cond2 = 0;
conds = [cond1, cond2];
tspan = [t(1) t(end)];
% y(1) = P(t), y(2) = M(t)
[T,y] = ode45(@MSolveFit,tspan,conds);
function dydt = MSolveFit(t,y)
nc = 2; % # monomers for primary nucleation
m0 = 10; % initial concentration of tau
mt = m0 - y(2);
% parameters :
% p(1) = kn
% p(2) = km
% p(3) = ka
% p(4) = kp
% dydt(1) = dPdt(t)
% dydt(2) = dMdt(T)
dydt = [0 0];
dydt(1) = p(1).*mt.^nc + p(2).*y(2) - p(3).*y(1).^2;
dydt(2) = p(4).*mt.*y(1);
end
end
Here's the error:
Error using odearguments (line 93)
MSOLVE/MSOLVEFIT must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Yaofit_chi2>MSolve (line 638)
[T,Y] = ode45(@MSolveFit,tspan,conds);
Error in lsqcurvefit (line 213)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in Yaofit_chi2 (line 625)
p = lsqcurvefit(@MSolve,pguess,t,f);
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!