4 views (last 30 days)

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.

Alan Weiss
on 20 May 2020

Alan Weiss

MATLAB mathematical toolbox documentation

Alan Weiss
on 24 May 2020

When I run

tt = objective_fun(param0,tspan)

I get a value tt of size 53-by-10. The size of ydata is 1-by-5. Clearly, these are not the same. Take a look at the documentation of lsqcurvefit to see what your objective function should return, compared to ydata.

My guess is that you forgot that you have two values of time, 0 and 5, and you are giving data only for time 5.

Alan Weiss

MATLAB mathematical toolbox documentation

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.