for loop doesn't seem to loop

3 ビュー (過去 30 日間)
Andrew Alkiviades
Andrew Alkiviades 2012 年 7 月 3 日
Hi I have the following code
for i = 1:8760
A = [PVtech(i,:) WTtech(i,:)];
b = demand(i);
f = [CRF*PVtechcost(i,:).*PVcap(i,:)./PVtech(i,:) CRF*WTtechcost(i,:).*WTcap(i,:)./WTtech(i,:)];
x(i) = linprog(f, A,b,[], [], lb);
end
I am trying to optimise linprog over the 8760 data set but I can't seem to get the loop going for each row. therefore when I run it is get a size of A to be 1x30 (when it should be 8760 by 30) Does anyone see where I have coded wrongly ?
thank you

採用された回答

Ryan
Ryan 2012 年 7 月 3 日
You're not specifying the row of A that you are writing the data to, so each loop it just places [PVtech(i,:) WTtech(i,:)] into the first row of A.
Try:
for m = 1:8760
A(m,:) = [PVtech(m,:) WTtech(m,:)];
b = demand(m);
f = [CRF*PVtechcost(m,:).*PVcap(m,:)./PVtech(m,:) CRF*WTtechcost(m,:).*WTcap(m,:)./WTtech(m,:)];
x(m) = linprog(f, A,b,[], [], lb);
end
  1 件のコメント
Sean de Wolski
Sean de Wolski 2012 年 7 月 3 日
same with x I believe.

サインインしてコメントする。

その他の回答 (2 件)

Thomas
Thomas 2012 年 7 月 3 日
編集済み: Thomas 2012 年 7 月 3 日
use ii instead of i since i is built into matlab for complex numbers
for ii=1:8760
ii % to show which loop you are in
A(ii,:)=[PVtech(ii,:) WTtech(ii,:)];
You also might have to change your
x(ii,:) = linprog(f, A(ii,:),b,[], [], lb)
Though I do feel that your program was running right just that you were only seeing the last A which will be 1x30 since it was being overwritten.
to see if you are going through the loop
just output ii
  2 件のコメント
Andrew Alkiviades
Andrew Alkiviades 2012 年 7 月 3 日
Still no luck! the ii output returns - 1 the size of A is still (1,30) and the size of b is still (1,1) A should be (8760x30) and b should be 8760x1
Ryan
Ryan 2012 年 7 月 3 日
Are you sure that you are showing us everything that is happening in the code? Doing something simplified such as:
for ii = 1:8760
A(ii,:) = 1;
end
returns an 8760x1 vector for me.

サインインしてコメントする。


Andrew Alkiviades
Andrew Alkiviades 2012 年 7 月 3 日
Thanks guys - I have made the changes you suggest,
I now get, from the code below, two rows of A so I have a size(A) = (2,30) where A should in fact be 8760x30
I don't see why the loop doesn't go through all the 8760 rows as it is
for i = 1:8760
A(i,:) = [PVtech(i,:) WTtech(i,:)];
b = demand(i);
f = [CRF*PVtechcost(i,:).*PVcap(i,:)./PVtech(i,:) CRF*WTtechcost(i,:).*WTcap(i,:)./WTtech(i,:)];
%options == optimset('LargeScale', 'off', 'Simplex', 'on');
x(i,:) = linprog(f, A,b,[], [], lb,[])
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by