Fmincon problems with A and b matrices that differ depending on for loop

Hi
Im doing a nonlinear optimization using fmincon that includes nonlinear equality constraints linear inequality constraints (These depend on values from two excel spreadsheets.
This is my code for the A and b matrices for j=1:3 for i=1:5
L = xlsread('hourly electric demand.xlsx');
Lth = xlsread('hourly thermal demand.xlsx');
if xin(1)>= L(j,i) && xin(2)>=Lth(j,i);
A(1,:)=[FIT RHI 0 0 -(FIT-Xe);-1 0 -1 0 0; 0 -1 0 -1 0];
b = [max(Pe*L(j,i))+Pth*max(Lth(j,i))+ Operation; -L(j,i);...
-Lth(j,i)];
elseif xin(1)<=L(j,i) && xin(2)<=Lth(j,i);
A(2,:)=[FIT RHI -Pe -Pth 0;-1 0 -1 0 0; 0 -1 0 -1 0];
b = [max(Pe*L(j,i)+Pth*Lth(j,i))+ Operation;-L(j,i); -Lth(j,i)];
elseif xin(1)>=L(j,i) && xin(2)<=Lth(j,i);
A(3,:)=[FIT RHI 0 -Pth -(FIT-Xe);-1 0 -1 0 0; 0 -1 0 -1 0];
b = [max(Pe*L(j,i)+Pth*Lth(j,i))+ Operation; -L(j,i); -Lth(j,i)];
elseif xin(1)<= L(j,i) && xin(2)>= Lth(j,i);
A(4,:)=[FIT RHI -Pe -Pth 0;-1 0 -1 0 0; 0 -1 0 -1 0];
b = [max(Pe*L(j,i)+Pth*Lth(j,i))+ Operation; -L(j,i); -Lth(j,i)];
end
end
end
and this is the code for the objective function
f = sum(((0.537*(L(j,i)-xin(1)))+(0.185*(Lth(j,i)-xin(2)))));
However I am getting the following error
??? Subscripted assignment dimension mismatch.
Error in ==> invoke at 42 A(1,:)=[FIT RHI 0 0 -(FIT-Xe);-1 0 -1 0 0; 0 -1 0 -1 0];
Do I need to make changes to the objective function since it only includes xin(1) and xin(2) whereas I am constraining to 5 difference xin?
thanks

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Jun. 2011

0 Stimmen

[FIT RHI 0 0 -(FIT-Xe);-1 0 -1 0 0; 0 -1 0 -1 0] is clearly 2 dimensional, but you are trying to assign it to a vector A(1,:) . That isn't going to work.

1 Kommentar

Thanks Walter
I have confused myself quite a bit (and with some basic maths)
do you have any suggestions on solving this issue?
thanks again

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrew Alkiviades
Andrew Alkiviades am 3 Jun. 2011

0 Stimmen

Thanks Walter
I have confused myself quite a bit (and with some basic maths)
do you have any suggestions on solving this issue?
thanks again

4 Kommentare

Consider that if you have an if/elseif structure that if the first branch is executed then the second branch never can be. Your code can therefore set only _one_ of A(1,:) or A(2,:) etc. Perhaps you should be assigning to _all_ of A ?
Could I not just leave it as A = and b = for all the 4 different ifs and elseifs since each if statement requires different values in the A matrix. Therefore just remove the A(1,:) etc?
Thanks Walter
p.s just a beginner it Matlab - sorry for the basic questions !
I suspect so, removing the (1,:) etc.
Thanks, I have tried that... Next question :)
i cant seem to find this error anywhere online.
??? Undefined function or method 'isfinite' for input arguments of type 'cell'.
Error in ==> C:\Program Files\MATLAB\R2010b\toolbox\optim\optim\barrier.p>barrier at 24
Do you have any idea what this may be?
Possibly in calling fmincon? which has been done by
options = optimset('Display', 'iter', 'Algorithm','interior-point');
[x,fval,exitflag]=fmincon(@myobjective,x0,A,b,[],[],lb,[],@confun2, options)

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by