Can't get the code into the for loop

Dear all, Please help me to get the attached code into the for loop. The code must run for j=1:length(Pd). Two variables are varying with every 'j' - Pd(j) and no_units(j). Of course the sizes of Pd and no_units are the same. I'm able to run it in a for loop for different Pd, but it doesn't work when I include no_units.
Many thanks, George.

5 件のコメント

Kevin Xia
Kevin Xia 2017 年 8 月 7 日
When I put the code in a for loop, I get the following error:
Error using *
Inner matrix dimensions must agree.
Error in LoopTest (line 29)
sigma=B(i,:)*Pg-B(i,i)*Pg(i);
The code fails because B is a 6x6 matrix, while Pg is a num_units x 1 vector. Pg needs to be a 6x1 vector for the matrix multiplication to work. Does the size of Pg need to depend on no_units?
George Ansari
George Ansari 2017 年 8 月 7 日
Hey Kevin, thanks for reply. Yes, the size of Pg is related to no_units. Infact, B, a, b, c, Pmax and Pmin are related to no_units. I'll try to explain: we are given with 6 power generating units, the code calculates optimal dispatch of the units. When all of 6 units are in use (no_units = 6), all listed variables are used in calculation, when, let's say first unit is not operating, no_units = 5; the values corresponding to the 1st unit must be deleted from B, a, b, c, Pmax and Pmin, so these vectors must become 1x5 vectors (instead of 1x6). Now I need to think how to implement it. Feel free to give your suggestions.
Thanks!
Kevin Xia
Kevin Xia 2017 年 8 月 7 日
編集済み: Kevin Xia 2017 年 8 月 7 日
Which numbers in the B matrix correspond to the first unit? Do the first column and the first row of correspond to the first unit?
George Ansari
George Ansari 2017 年 8 月 8 日
Kevin, yes, I suppose it should be that way.
KL
KL 2017 年 8 月 8 日
it doesn't work when I include no_units
show us what you've tried. Simply attaching your m-file and asking us to do your work is not the point.

回答 (0 件)

この質問は閉じられています。

タグ

質問済み:

2017 年 8 月 7 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by