Adding available capacity at the hourly time increment

Hello,
Could you please help me how to cumulate available capacity that is second column of G matrix (10,10,15,15,15) at the hourly time increment. When random number is larger or equal to number from third column of G matrix, these capacities should be cumulated for every time iteration of 1 to 500.
For example, if i=1 => Sum=10+0+15+15+0=40; i=2 => Sum=0+10+15+0+0=25; i=3 => Sum=10+10+0+15+15=50 and so on until 500 iteration. I hope it is clear enough what I want to do.
G=[1,10,0.05;2,10,0.05;3,15,0.03;4,15,0.03;5,15,0.03];
for i=1:500
for j=1:length(G)
X=rand(1);
if X>=G(j,3)
K=G(j,2);
else
K=0;
end
end
end

3 件のコメント

Guillaume
Guillaume 2018 年 11 月 15 日
編集済み: Guillaume 2018 年 11 月 15 日
" I hope it is clear enough what I want to do."
No. I don't understand why for i = 1 you don't add row 2 and 5, for i = 2 you don't add row 1, 4 and 5 and for i = 3 you don't add row 3. There seems to be no logic to that. You need to explain better.
edit: and your code doesn't help at all. notwithstanding the fact that it will error if G has less than 3 rows, it doesn't make much sense. The whole lot is equivalent to:
G=[1,10,0.05;2,10,0.05;3,15,0.03;4,15,0.03;5,15,0.03];
K = G(end, 2) * (rand >= G(end, 3)); %since K is never indexed, only the last step of the loop matters
Banjo
Banjo 2018 年 11 月 15 日
Basically I just want that every of 500 hourly iterations represent a summation of available capacity for 5 generators. Generator capacity is available if X>=G(j,3). Regards
Guillaume
Guillaume 2018 年 11 月 15 日
What is X? What is capacity? What is a generator? Where is time so we understand what an hourly iteration is?
We have absolutely no idea what your data represent and you don't explain it. Your basically doesn't give us the basics I'm afraid.

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

回答 (2 件)

madhan ravi
madhan ravi 2018 年 11 月 15 日

0 投票

have you seen cumsum?

1 件のコメント

Banjo
Banjo 2018 年 11 月 15 日
When I put cumsum(K)
G=[1,10,0.05;2,10,0.05;3,15,0.03;4,15,0.03;5,15,0.03];
for i=1:500
for j=1:length(G)
X=rand(1);
if X>=G(j,3)
K=G(j,2);
else
K=0;
end
end
cumsum(K)
end
I get for example
K = 10
K = 10
K = 0
K = 15
K = 15
ans = 15
but as an answer I should get
ans = 50

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

per isakson
per isakson 2019 年 12 月 23 日

0 投票

This answer is a variation of my answer to your recent question, "Storing and passing all iterations to an array outside the nested for loops"
>> clearvars
>> cssm
>> h = plot(sum(K,2),'.');
>> h.Parent.YLim = [33,67];
Produces 500 realizations of whatever your code represents. The results range from 35 to 65.
Capture.PNG
where the script, cssm, is your script with a few modifications
%%
G=[1,10,0.05;2,10,0.05;3,15,0.03;4,15,0.03;5,15,0.03];
K = nan( 500, length(G) ); % pre-allocate
for ii=1:500
for jj=1:length(G)
X=rand(1);
if X>=G(jj,3)
K(ii,jj)=G(jj,2);
else
K(ii,jj)=0;
end
end
end

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2018 年 11 月 15 日

回答済み:

2019 年 12 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by