필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Dustyn Roberts
Dustyn Roberts 2014년 5월 22일
댓글: Matt J 2014년 5월 22일
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
Matt J
Matt J 2014년 5월 22일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2014년 5월 22일
편집: Matt J 2014년 5월 22일
It sounds like your initial guess x0 is still 72x1, and not 73x1 as you intended.
  댓글 수: 2
Matt J
Matt J 2014년 5월 22일
편집: Matt J 2014년 5월 22일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by