Running a simulation with different parameters on each loop

5 ビュー (過去 30 日間)
Maitiumc
Maitiumc 2017 年 2 月 15 日
コメント済み: John Chilleri 2017 年 2 月 15 日
So basically I am modelling a hybrid PV-wind energy system. The main components effecting output are the number of PV arrays, the number of wind turbines and the number of batteries; nPV, nW and nB respectively.
So I want to run this using all possible combinations, eg 1-maxPv, 1-maxW and 1-maxB. I have the algorithm coded up to the point where the timestep t reaches the end. At which point it should then increase one of the parameters and run again.
I'm not sure what the best way to go about this would be. Would it be possible to construct a matrix of all the possible combinations and somehow use this in the loop for the nPV/nW/nB values at that instant? Or maybe a while loop which runs until all 3 values are at the max value (though I wouldn't be sure how I can code that without huge amount of if statements for each combination, and there's already a lot of ifs/elseifs in there already)
Any suggestions appreciated.
  2 件のコメント
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017 年 2 月 15 日
This is what 'for' loops are meant to do. Are you familiar with for loops?
Maitiumc
Maitiumc 2017 年 2 月 15 日
Yes I am. But I struggle to see how it can be used well. I will need to run the model with 1 to 10 PV, and 1:2W, 1:10B, and run all possible combinations
so sure, I can say
for n=1:10
nPV = n
end
Similarly for the other two parameters, but how can I fix two or one parameters while I increment the other(s) and then reset the others once I'm ready to increment the one(s) I had leaving constant as I was increment the other?
for m=1:10
nPV = m
for n = 1:2
nW=n
end
for p =1:10
nB = p
end
end
Maybe I've been staring at screens too long, but won't this method miss out on some possible combinations?

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

採用された回答

John Chilleri
John Chilleri 2017 年 2 月 15 日
Hello,
Kaushik Lakshminarasimhan was correct, for loops will check all options:
for nPV = 1:10
for nW = 1:2
for nB = 1:10
% do whatever
end
end
end
nPV will be one and nW will be one while nB runs through everything else. Then nPV will be one, nW will be two while nB runs through everything else. Then nPV will be two, nW will start back at one, nB will run through everything, and it will repeat until all combinations have been checked.
Make sure you have them nested as I showed above.
Hope this helps!
  1 件のコメント
John Chilleri
John Chilleri 2017 年 2 月 15 日
To be confident it contains all combinations, consider this.
With 1:10, 1:2, and 1:10, there are 10 x 2 x 10 combinations, so 200 combinations.
If you run
count = 0;
for nPV = 1:10
for nW = 1:2
for nB = 1:10
count = count+1;
end
end
end
Then you'll see,
>> count
count =
200

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by