How to use optimizer with ode45?

2 visualizzazioni (ultimi 30 giorni)
Murad Nazari
Murad Nazari il 26 Feb 2018
Commentato: James Tursa il 27 Feb 2018
I have an ordinary differential equation (dT/dt) = (5.4675e-4)q. I have a data set of T vs t where T is temperature and t is time. I want to determine q such that the T calculated from the differential equation will fit the T recorded in the lab. As part of classwork, my professor asked me to use ode45 and optimizer to fit the data to the ODE. I don't know where to start?
Any help will be appreciated.

Risposte (2)

James Tursa
James Tursa il 26 Feb 2018
You would start by writing code to numerically integrate your DE using ode45. You have a simple 1st order ODE. There is an example in the ode45 doc showing how to do a 1st order ODE. Start with that and modify it with your equation using the time span of your data.
Once you have that working, wrap your ode45 stuff inside of a function where you pass in q to the function.
Then ask yourself how you would use an optimizer on this function to minimize the difference between what your function produces for a given q to what your measurements are.
  2 Commenti
Murad Nazari
Murad Nazari il 27 Feb 2018
Thanks for the answer. T'=(5.4675e-4)qdt has one extra unknown q. How can I deal with that?
James Tursa
James Tursa il 27 Feb 2018
Just put that as a parameter in your derivative function. E.g.,
q = something;
deriv = @(t,y) (5.4675e-4)*q;
Then pass deriv to ode45 as the 1st argument. Just be sure that every time you change q, you redefine the deriv function handle (otherwise it will continue to use the old q).

Accedi per commentare.


Star Strider
Star Strider il 26 Feb 2018
If you are fitting your differential equations to data, see Monod kinetics and curve fitting (link), Solving Coupled Differential Equations (link), and Parameter Estimation for a System of Differential Equations (link).
Optimizing differential equations is actually an example in the documentation for the Optimization Toolbox: Optimizing a Simulation or Ordinary Differential Equation (link).

Community Treasure Hunt

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

Start Hunting!

Translated by