ODE15s vectorization in GA Optimization

2 views (last 30 days)
Antonio Intini
Antonio Intini on 22 Nov 2020
Edited: Antonio Intini on 23 Nov 2020
Hi there,
I'm trying to optimize a certain system. I'm using ga. There I've selected the 'UseVectorized' option.
options=optimoptions('ga','UseVectorized',true,'PopulationSize',popsize,'InitialPopulationMatrix',population);
I also provide a small initial population (17) for sake of initial tests. The problem has 16 variables.
[x,fval]=ga(@optimize_exp07_1,16,[],[],[],[],[],[],[],options);
The function @ODEfun is then integrated in regard to its 19 differential equations.
options = odeset('RelTol',1e-9,'Vectorized','on','MaxStep',1e-1);
[t,y]=ode15s(@ODEfun,experiment.timespan_min,y0,options);
Note that I selected 'Vectorized' as 'on' here as well. The @ODEfun, which calculate the derivatives, receives the following initial values y0:
The output (derivatives) is generated as follows:
The problem is, in whatever format I try to return these derivatives, I get error from odeset:
19x17:
Error using odearguments (line 93)
POLYMERIZE/ODEFUN must return a column vector.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in polymerize (line 54)
[t,y]=ode15s(@ODEfun,experiment.timespan_min,y0,options);
323x1 (column vector):
Index exceeds matrix dimensions.
Error in odenumjac (line 151)
absFdelRm = abs(Fdel((0:ny-1)*nF + Rowmax));
Error in ode15s (line 353)
[dfdy,Joptions.fac,nF] = odenumjac(odeFcn, {t,y,odeArgs{:}}, f0, Joptions);
Error in polymerize (line 54)
[t,y]=ode15s(@ODEfun,experiment.timespan_min,y0,options);
Do you have any suggestion on how to make this vectorization of ODE15s work in this problem?
Thanks in advance!
  3 Comments
Antonio Intini
Antonio Intini on 23 Nov 2020
Like I mentioned above, I tried the column vector, and it returns an error (”exceeds matrix dimension”)
Antonio Intini
Antonio Intini on 23 Nov 2020
Edited: Antonio Intini on 23 Nov 2020
Some additional information, in case someone can help.
When I pass a column vector as the return for ODE15s, the "exceeds matrix dimension" occurs at line 151 of odenumjac:
absFdelRm = abs(Fdel((0:ny-1)*nF + Rowmax));
Fdel is 323x1, while ny is 1x1. The operation (0:ny-1) generates a 1x323 matrix. So it tries to compute out of the possible index. As ny is correct, Fdel probably isn't.
Fdel is initiated in odenumjac.m on line 135:
% Expand arguments. Need to preserve the original (non-expanded)
% Fargs in case of correcting columns (done one column at a time).
Fargs_expanded = Fargs;
Fargs_expanded{diffvar} = ydel;
vectvar = setdiff(vectvar,diffvar);
for i=1:length(vectvar)
Fargs_expanded{vectvar(i)} = repmat(Fargs{vectvar(i)},1,ny);
end
Fdel = feval(F,Fargs_expanded{:});
The for loop uses vectvar, which is 0 (initial vectvar=2 and diffvar=2). The output is the 323x1 matrix, which turns out to be incompatible with the line 151.
Any guess? Is there any option I'm forgetting to include either in ga or ODE15s?

Sign in to comment.

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!