How to solve multiple optimization problems parallelly?
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?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? 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? fmincon, optimization MATLAB Answers — New Questions