optimizing two variables in fmincon with different sizes

7 次查看(过去 30 天)
I have a nonlinear optimization problem where I want to optimize an n x n matrix A and an n x 1 vector b. How can I set up the problem so that fmincon can solve it? Assume that the objective is 0 with no equality or inequality constraints. How can I set up the nonlinear constraint function nonlcon and the inital conditions. How can I get two output from fmincon?

回答(1 个)

Walter Roberson
Walter Roberson 2022-3-10
You cannot directly pass two inputs to be optimized to fmincon, and you cannot directly return two outputs from fmincon.
What you should do is create a vector of values, taking either [b, A] or [A, b] and reshaping to a vector. Inside your objective function, extract the appropriate components from the input vector and reshape as needed:
function cost = myobj(x)
b = reshape(x(1:50), [], 1);
A = reshape(x(51:end), 50, 50);
do your stuff
end
Construct your constraints around the same vector configuration.
x0 = reshape([b0, A0], [], 1);
fmincon(@myobj, x0, ....)
I would suggest that in your case, you have a look at Problem Based Optimization, which will automatically do all packing and unpacking for you (but depending on the complexity of your objective and constraints might have some trouble calculating some values.)

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by