MATLAB: Optimisation of function containing matrix

optimization

I am having trouble optimising this system. I have been trying to use fmincon without success.
C is a 16×16 matrix, mo and v and 1 are 16×1 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…

Best Answer

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