1
votes

I have a fairly complex optimization problem set up that I've solved through fmincon by calling it like this

myfun = @(x5) 0.5 * (norm(C*x5 - d))^2 + 0.5 * (timeIntervalMeanGlobal * powerAbsMaxMaxGlobal * sum(x5(28:128),1))^2;
[x5, fval] = fmincon(myfun, initialGuess, -A, b, Aeq, beq, lb, []);

The components are far to long to print here, but here are the dimensions

C: 49 x 128  
x5: 128 x 1  
d: 49 x 1  
timeIntervalMeanGlobal, powerAbsMaxMaxGlobal: constants  
initialGuess: 128 x 1  
A: 44541 x 128  
b: 44541 x 1  
Aeq: 24 x 128  
beq: 24 x 1  
lb: 128 x 1  

This works in code, but I don't get results that I'm completely happy with. I'd like to compare it with the built in ga function in MATLAB, which is called in a similar way, but I get an error when I try to run it like this

[x5, fval] = ga(myfun, nvars, -A, b, Aeq, beq, lb, []);  

where nvars = 128. There's a long list of about 8 errors starting with

??? Error using ==> mtimes
Inner matrix dimensions must agree.

and ending with

Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.

Can someone please instruct me on how to call ga properly, and give insight on why this error might occur with the ga call when the same code doesn't cause an error with fmincon? I've tried all the MATLAB help files and examples with a few different permutations of this but no better luck. Thanks.

UPDATE: I think I found the problem but I don't know how to fix it. The ga documentation says "The fitness function should accept a row vector of length nvars". In my case, myfun is the fitness function, but x5 is a column vector (so is lb). So while mathematically I know that C*x5 = d is the same as x5'*C' = d' even for non-square matrices, I can't formulate the problem that way for the ga solver. I tried - it makes it past the fitness function but then I get the error

The number of rows in A must be the same as the length of b.

Any thoughts on how to get this problem in the right format for the solver? Thanks!

1
What is your value for nvars? Your mtimes error means that MATLAB complains that matrix multiplication doesn't have the number of columns in the first matrix equal the number of rows in the second.Franck Dernoncourt
nvars = 128. It's a constant, so I don't see how that would cause the error. Thanks.dustynrobots
There's a comment in my inbox I don't see here that says "Can you try it with nvars = 1?". I did this and it gets rid of the mtimes error, but then I get another dimension mismatch error: ??? Error using ==> preProcessLinearConstr at 49 The number of columns in A must be the same as the length of X0.dustynrobots
Yep I removed it as on second thought nvars = 128 should be good.Franck Dernoncourt

1 Answers

1
votes

Got it! I just had to manipulate the fitness function to make it use x5 as a row vector even though it's a column vector in all the constraints

myfun = @(x5) 0.5 * (norm(x5 * C' - d'))^2 + 0.5 * (timeIntervalMeanGlobal * powerAbsMaxMaxGlobal * sum(x5(28:128)))^2;

Phew!