fmincon with matrix inputs --> nonlinear cost function and constraints

1 view (last 30 days)
I have a myfun.m file that defines the following function:
f = 0.5 * (norm(C*x - d))^2;
and it is called in a main script by:
[x, fval] = fmincon(@myfun, x0, -A, b, Aeq, beq, lb, ub);
C is a 170x72 matrix, d is a 170x1 vector, so x is a 72x1 vector. This part works well.
Now I want to multiply each element of C by a constant raised to a power, and solve for that power. So instead of C(1,1) = 4, now it should be = (2^p)*4. However, I want p to be solved for in the optimization as well, so p = x(73). I realize that augmenting the x matrix means I have to update x0, A, b, Aeq, beq, lb, ub to all include 73 elements, which I've done. The problem arises when I define the elements of the C matrix like C(1,1)= (2^x(73))*4, I get the: "Index exceeds matrix dimensions" error The new x(73) element has no constraints or bounds associated with it. Any thoughts on why this is not working or how to fix it? Is it somehow invalid to use an element of x inside C, then multiply by x as I do in the cost function?
Note: I realize this cost function looks just like least squares. I used fmincon originally since I had multiple objectives, and will continue to use it after I solve this problem because I need to add in nonlinear constraints.
  1 Comment
Matt J
Matt J on 22 May 2014
The problem arises when I define the elements of the C matrix like C(1,1)= (2^x(73))*4
If the base appearing in C(i,j)(in this case the 2 in 2^x(73)) is a constant independent of (i,j), then there is no need to be modifying C. You could just rewrite the cost function as
f = @(x) 0.5 * (norm( C* (x(1:72)*2^x(73) ) - d))^2;
and this would be more efficient because 2^x(73) is now multiplied with only the 72 elements of x(1:72) instead of the 12240 elements in C.

Sign in to comment.

Answers (1)

Matt J
Matt J on 22 May 2014
Edited: Matt J on 22 May 2014
It sounds like your initial guess x0 is still 72x1, and not 73x1 as you intended.
  2 Comments
Matt J
Matt J on 22 May 2014
Edited: Matt J on 22 May 2014
I don't think any further advice is possible without code that we can run ourselves. I suggest you attach a .mat file containing x0, A, b, Aeq, beq, lb, ub, so that we can try to reproduce what you see.

Sign in to comment.

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!