How to solve multiple optimization problems parallelly?
Mostrar comentarios más antiguos
I try to solve an optimization problem with "fmincon" function in "matlab function block" in the Simulink environment.
The current code is (for example):
function y = fcn(input1, input2)
persistent x
if isempty(x)
x = [x1_0, x2_0]; % initial condition
end
fun = @(x)("designed costfuntion J(x(1),x(2),input1,input2)") %not my cost funciton, just for illustration
lb = [x1_l, x2_l];
ub = [x1_h, x2_h]; %lower and upper bound
options = optimoptions('fmincon','Display','iter','Algorithm','sqp','StepTolerance',1e-18);
[x,fval,exitflag] = fmincon(fun,x,A,b,Aeq,beq,lb,ub,nonlcon,options);
end
The problem is that when the input signals from other Simulink blocks have the dimension of 1, it works fine.
However, I want to make input signals have the dimension of 30, like sovling 30 same problems parallely, and output the x1* and x2* with the dimension of 30, too. When I fed multi-dimensional input signals to the matlab function, it returned:
Simulink cannot determine sizes and/or types of the outputs for block 'matlab function name' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Error in port widths or dimensions. 'Output Port 1' of 'matlab function name' is a one dimensional vector with 30 elements.
Is there any efficient way to handle this situation? Or other nonlinear optimization tool can work with multi-dimensional input signals?
3 comentarios
Matt J
el 3 de Feb. de 2025
It's not worth it. Just loop over your input1 and input2 explicitly.
Pat
el 3 de Feb. de 2025
Walter Roberson
el 3 de Feb. de 2025
There is no inherent problem in using persistent in a loop. Using a structure such as
persistent x
if isempty(x)
x = [x1_0, x2_0]; % initial condition
end
should work technically.
However, there is the issue that if you are using continuous time, that Runge-kutta type of solvers search around in multiple locations in order to decide on the correct direction, and may even reject steps and go backwards, so the solution for one time might not be tightly tied to the best solution for the next call.
Respuestas (0)
Categorías
Más información sobre Nonlinear Control en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!