How to use optimizer with ode45?

3 次查看(过去 30 天)
Murad Nazari
Murad Nazari 2018-2-26
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.

回答(2 个)

James Tursa
James Tursa 2018-2-26
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 个评论
Murad Nazari
Murad Nazari 2018-2-27
Thanks for the answer. T'=(5.4675e-4)qdt has one extra unknown q. How can I deal with that?
James Tursa
James Tursa 2018-2-27
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).

请先登录,再进行评论。


Star Strider
Star Strider 2018-2-26
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).

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by