Multiple initial points in fmincon optimization
显示 更早的评论
Hi
Thank you for reading this question!
I am studying "Fmincon" in Matlab. Based on "Fmincon" document, I wrote a code, as shown below.
close all;
clear;
clc;
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2; % objective function
x0 = [-1, 2; -1, 2; -1, 2]'; % initial points
Aeq = [0.5, 0.1, 0, 0, 0, 0; 0, 0, 2, 1, 0, 0; 0, 0, 0, 0, 0.2, 2]; % constraints
beq = [1; 1; 1]; % constraints
[x,fval] = fmincon(fun,x0,[],[],Aeq,beq)
In this code, x0 contains six elements. Then, Aeq needs six columns of elements. Based on "Fmincon" document, Equality constraint equation can be written as below:
0.5*x(1)+0.1*x(2)+x(3)+x(4)+x(5)+x(6)=1 (1)
x(1)+x(2)+2*x(3)+x(4)+x(5)+x(6)=1 (2)
x(1)+x(2)+x(3)+x(4)+0.2*x(5)+2*x(6)=1 (3)
In fact, objective function only includes two variables that are x(1) and x(2). Therefore, how does this code ("Fmincon") work? I have not found the similar question in the community. Could anyone explain it or share the relevant link?
Many thanks in advance!
采纳的回答
更多回答(1 个)
Jon
2023-4-10
0 个投票
As @Alan Weiss points out it seems that you are misunderstanding how MATLAB interprets the 2 by 3 array you are inputting as x0. You are thinking that you are optimizing to find the optimum value of a two element vector, with elements x(1) and x(2), and you think that each column of x0 is a different initial guess.
Infact MATLAB only allows one initial guess. So it interprets your 6 element array of x0's as telling it that you are optimizing to find 6 values (that happen to be in a 2 by 3 array). It then uses linear indexing (numbering elements columwise) to find the initial values of x, so x(1) = x0(1,1), x(2) = x0(2,1), x(3) = x0(1,2), x(4) = x(2,2) etc. It doesn't mind that your objective function only uses the first two of these six elements, but uses all 6 when evaluating the constraints.
类别
在 帮助中心 和 File Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!