Probably simple - ode45 and lsqcurvefit
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Rhys
am 26 Mai 2014
Kommentiert: Star Strider
am 26 Mai 2014
This is probably really trivial, but what I need is a function that takes a vector of parameters and a vector of time and, with ode45, outputs the p values of the ode: dp/dt=b*p-d*p^2.
What I have is:
function dpdt=diffeqn(t,p,par)
b=par(1);
d=par(2);
dpdt=b*p-d*p^2
end
and then a separate script:
[year pdata]=ode45(@diffeqn,[year],p0,[],[0.015,0.001]);
disp(pdata)
This does work fine for what is needed, but I think I need this all in one function, in order to call it in a lsqcurvefit command.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 26 Mai 2014
Not trivial, but not obvious either. I did this a while back in my answer to Monod kinetics and curve fitting.
Your equations are fine. To use lsqcurvefit, you just need to wrap them inside the objective function you send to it.
You can even include the initial conditions in the parameters to be estimated if necessary. That’s something we can discuss later if you need to do it.
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Historical Contests finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!