Optimisation of function containing matrix

1 次查看(过去 30 天)
I am having trouble optimising this system. I have been trying to use fmincon without success.
C is a 16x16 matrix, mo and v and 1 are 16x1 vectors. I want to choose mo to maximise x = c*mo+v
The constraints are: the components of mo must add to one (I think I've done this one)
and each component of x should be equal, that is x1=x2=...=x16 where x=c*mo+v (I have no idea how to represent this)
fun = @(mo) -C*mo-v;
A=[];
b=[];
Aeq= ones(1,16);
beq= 1;
lb = zeros(16,1);
ub = ones(16,1);
m0 = 1/16*ones(16,1);
mo = fmincon(fun,m0,A,b,Aeq,beq,lb,ub)
Please let me know where I'm going wrong...
  3 个评论
Isabelle Steinmann
Isabelle Steinmann 2019-10-10
C =
Columns 1 through 10
1.0003 0.0245 0.0052 0.0172 0.0273 0.0220 0.0171 0.0208 0.0073 0.0218
0.0054 0.9994 0.0100 0.0326 0.0329 0.0369 0.0173 0.0155 0.0224 0.0269
0.0152 0.0097 1.0001 0.0173 0.0374 0.0220 0.0222 0.0208 0.0174 0.0219
0.0001 -0.0000 0.0000 1.0005 0.0255 0.0054 0.0103 0.0101 0.0007 0.0057
0.0001 -0.0000 0.0000 0.0056 1.0006 0.0103 0.0052 0.0050 0.0055 0.0204
0.0001 -0.0003 -0.0000 0.0059 0.0108 1.0007 0.0009 -0.0097 0.0156 0.0054
0.0001 -0.0001 -0.0000 0.0112 0.0110 0.0255 1.0005 0.0001 0.0359 0.0105
0.0001 -0.0001 -0.0000 0.0112 0.0110 -0.0041 0.0257 1.0004 0.0262 0.0156
0.0000 -0.0003 -0.0000 0.0205 0.0008 0.0005 0.0005 0.0002 1.0005 0.0003
0.0001 -0.0001 -0.0000 0.0157 0.0011 0.0105 0.0056 0.0053 0.0108 1.0004
0.0001 -0.0002 -0.0000 0.0111 0.0210 0.0157 0.0162 0.0152 0.0213 0.0009
0.0000 -0.0003 -0.0000 0.0107 0.0154 0.0007 0.0150 -0.0000 0.0155 0.0054
0.0050 -0.0104 -0.0001 0.0213 0.0212 0.0164 0.0456 0.0151 0.0169 0.0159
-0.0001 -0.0200 -0.0001 0.0095 -0.0004 0.0092 -0.0102 -0.0052 -0.0006 0.0047
0.0000 -0.0101 -0.0001 0.0102 0.0054 0.0151 0.0006 -0.0099 0.0002 0.0001
0.0100 -0.0000 0.0000 0.0158 0.0309 0.0058 0.0007 0.0005 0.0057 0.0158
Columns 11 through 16
0.0213 0.0179 0.0317 0.0165 0.0165 0.0064
0.0068 0.0479 0.0367 0.0270 0.0316 0.0213
0.0216 0.0228 0.0316 0.0167 0.0164 0.0163
0.0005 0.0055 0.0002 0.0003 0.0002 0.0155
0.0007 0.0007 0.0003 0.0003 0.0002 0.0203
0.0152 0.0307 0.0204 0.0109 0.0107 0.0002
0.0158 0.0264 0.0008 0.0110 0.0007 0.0104
0.0158 0.0212 0.0054 0.0009 0.0055 0.0106
0.0149 0.0205 0.0053 0.0203 0.0053 0.0002
0.0205 0.0060 0.0056 0.0005 0.0054 0.0152
1.0009 0.0214 0.0204 0.0010 0.0058 0.0006
0.0002 1.0008 0.0004 0.0153 0.0200 0.0005
0.0159 0.0169 1.0008 0.0257 0.0202 0.0009
-0.0150 0.0041 0.0043 0.9998 -0.0103 -0.0002
0.0002 0.0151 0.0199 0.0004 1.0003 -0.0000
0.0154 0.0108 0.0057 0.0104 0.0054 1.0008
v is a zero vector

请先登录,再进行评论。

采纳的回答

Fabio Freschi
Fabio Freschi 2019-10-10
编辑:Fabio Freschi 2019-10-11
While waiting for the data, I try to solve one of the questions. you can set the missing constraint as
x1-x2 = 0
x2-x3 = 0
...
so, let's call M the matrix with +1 -1 along the diagonal
M = diag(ones(16,1),0)+diag(-ones(15,1),1);
The last row has to be removed
% remove last row
M = M(1:end-1,:);
now, x = C*mo+v and we want M*x = 0, so Mx = M*C*mo+M*v = 0 and the new equality constraint is
% new constraints
Aeq2 = M*C;
beq2 = -M*v;
% append
Aeq = [Aeq; Aeq2];
beq = [beq; beq2];
However, the main problem is that your objective function returns a vector and not a scalar quantity. I don't know your problem but is the sum of all x a feasible objective function to maximize?
fun = @(mo) -sum(C*mo+v);
In this case the solution is
>> mo
mo =
0.0549
0.0481
0.0524
0.0668
0.0672
0.0644
0.0615
0.0627
0.0661
0.0655
0.0623
0.0653
0.0570
0.0737
0.0689
0.0633
>> sum(mo)
ans =
1
>> C*mo
ans =
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
0.0720
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by