2
votes

This may be really simple question for MATLAB fmincon users:

I have a function Y = AX, where A is a vector 1 x N of constants, Y is a scalar constant, and X is a vector N x 1; I need to find the optimal values of X such that Y - A*X = 0. Initial values for X come from a N x 1 vector X0. Also

X0(1) < X0(2) < ... X0(N)

The constraints are:

0 <= X(1);
X(1) < X(2);
X(2) < X(3);
...
...
X(N-1) < X(N);
X(N) <= 1;

and

X0(1) <= X(1);
X0(2) <= X(2);
X0(3) <= X(3);
...
...
X0(N-1) <= X(N-1);

My attempt at this problem was:

[X, fval] = fmincon(@(X)Y - A*X, X0,[],[],[],[],X0,[X(2:end);1],[],options);

I don't think the results I get are correct with this method. Another attempt was this:

[X, fval] = fmincon(@(X)Y - A*X, X0,AA,zeros(N-1,1),[],[],[],[],[],options);

where

AA = [1 -1 0 0 0 ... N;
      0 1 -1 0 0 ... N;
      .
      .
      0 0 0 0 0 ... 1 -1];  (N-1 Rows)

with failure as well.

Any suggestions, hints would be very welcome! I hope I have given enough information regarding the problem.

Following Shai's suggestion I have tried this :

[X, fval] = fmincon(@(X) abs(Y - A*X), X0,AA,eps(0)*ones(N-1,1),[],[],X0,[],[],options);

But no success. After exactly N iterations the solution converges to X0. I used the abs to get Y - AX to minimize to 0, and X0 in the lower bound to satisfy the conditions X0(1) < X(1) etc..

Thanks Shai, using the artificial / dummy objective function, was a great idea. However when I use linprog in the following way :

[X, fval] = linprog( -(1:N), AA, -eps(0)*ones(N-1,1), ...
                         A, Y, X0, [], X0, options ); 

I get the problem that Y is a scalar and A is still a N x 1 vector. and linprog expects Y to be a vector as well. That changes the problem of course. I set the lower bound to X0, upper bound empty (since the inequality constraint takes care of it), and set the initial values to X0. So still not working. Will update if any resolution occurs.

1
1. change A to A.' so you'll have a single equality constraint with Y as its left hand side (a scalar). leave zero and one as lower and upper bounds. You'll have to be more specific about "not working". please leave comments with "@shai" so I'll be notifiedShai

1 Answers

1
votes

I can see no reason why we cannot find an X for which A*X = Y exactly (there should be enough degrees of freedom for sufficiently large N). So instead of making |A*X-Y| the objective function to be minimize, I suggest adding A*X=Y as a constraint.
Moreover, to encourage Xi < Xj for i<j I suggest an "artificial" objective function -(1:N) that will put larger weight on Xj for large j.

[X, fval] = fmincon( @(X) -(1:N)*X(:), X0, AA, -eps(0)*ones(N-1,1), ...
                                           A, Y, zeros(N,1), ones(N,1), [], options); 

And while we are at it, why aren't you using linear programing - this should work better than the general purpose fmincon as it is tailored for the linear case?

[X, fval] = linprog( -(1:N), AA, -eps(0)*ones(N-1,1), ...
                             A, Y, zeros(N,1), ones(N,1), X0, options );