Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Dustyn Roberts
Dustyn Roberts le 22 Mai 2014
Commenté : Matt J le 22 Mai 2014
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 commentaire
Matt J
Matt J le 22 Mai 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.

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 22 Mai 2014
Modifié(e) : Matt J le 22 Mai 2014
It sounds like your initial guess x0 is still 72x1, and not 73x1 as you intended.
  2 commentaires
Dustyn Roberts
Dustyn Roberts le 22 Mai 2014
Nope, that's not it
Matt J
Matt J le 22 Mai 2014
Modifié(e) : Matt J le 22 Mai 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Problem-Based Optimization Setup dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by