MATLAB: Solve optimization problem that iterates on parameters with constraints defined with numerical solutions to differential equations depending on those parameters

differential equationsnumerical integrationoptimization

I want to search for an optimum in a problem where the constraints are numerical solutions of differential equations (these equations don't have analytical solutions) but the parameters I want to iterate on are parameters that appear in the differential equation so that the solver would need to:
  • compute the numerical solution to the differential equations with current parameters
  • check if my constraints on the numerical solutions are verified and compute
  • if they are not, change parameters and compute the numerical solutions again to see if it gets closer
  • once they are, try to minimize my objective function (which is also a function of these parameters) which to complicate even more is the maximum value in a vector
I don't have a lot of code to show because I don't know where to begin but basically I would like to do this :
objective: minimize (max(k))
constraints:
I=1;
k01=0.1;
theta_0=deg2rad(5);
k12=0.1;
theta_2=deg2rad(5);
Fm=10;
Fg=0.1;
l=30*10^(-3);
tspan = [0 5];
theta0 = [deg2rad(10) 0];
function dthetadt = odefcn(t,theta,k,I,theta_0,theta_2,Fm,Fg,l,n)
dthetadt = zeros(2,1);
dthetadt(1) = theta(2);
dthetadt(2) = (1/I)*(-k(1)*(theta(1)-theta_0)-k(2)*(theta(1)-theta_2)+Fm*l*sin(theta(1))-Fg*l*cos(theta(1)));
end
[t,theta] = ode45(@(t,theta) odefcn(t,theta,k), tspan, theta0);
theta(t_final)-theta_objective < tol
I guess come optimization toolboxes offer this possibility but I can't find one.
Thanks in advance.

Best Answer

Perhaps the example Fit an Ordinary Differential Equation (ODE) can help.
Alan Weiss
MATLAB mathematical toolbox documentation