How to use if and else statement for different tilmestep
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I am working ob the code, I need Bin same matrix as MSL and QSL in the answers. Howver, I am not geeting correct answer.
The first step where T=1, calculated Bin should be used in second timesep when t=2 to 6. but answer is not coming correct, Bin should be different for each c1,c2.c3 and c4 combination. Please can somebody help . It's important. I have tried everything. I have mentioned incorrect anser where Bin is taking row and his 2 column. Something is wron with the time loop. Please help. I am very new to Matlab
q=[
0.000585366
0.015219512
0.100829268
0.153512195
0.211317073
];
c1=[2.913953437
0.357062085
15.85599407
2.345265863
0.46210313
8.900276197
0.916228389
0.464613769
0.50948815
3.625787133
];
c2=[0.381190238
2.378275189
0.145437759
0.373540574
2.071089271
0.197531521
0.777306452
1.590828583
1.401326121
0.381022168
];
c3=[1.357856932
1.393019098
1.239392127
1.740872069
1.921689678
1.041252003
0.974309699
0.516968399
1.098337754
0.636148757
];
c4=[1.634449245
1.455924213
1.172657972
1.114923556
0.459329589
0.263155864
1.640481459
0.547592137
1.999694643
0.589185378
];
ADP=2.37;
time= [0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
];
N = length(q);
M = length(c1);
QsL = zeros(M,N);
msL = zeros(M,N);
Bini=zeros (M,N);
for t=1:N
if t==1
Bini(:,t) = c1.*(1-exp(-ADP*c2))*24.6*10^6;
QsL(:,t) =c3.*q(t).^c4.*Bini(t);
msL(:,t)=QsL(t)*time(t);
else
Bini(:,t)=Bini(:,t)-msL(:,t-1);
QsL(:,t) =c3.*q(t).^c4.*Bini(t);
msL(:,t)=QsL(:,t)*time(t);
end
end
W_sim=QsL;
Bin= 42638546.2763492 8752405.80468670 113724270.579282 33829000.4087649 11247945.2737427
8752410.82845347 8752405.80468670 113724023.618417 33795998.8664633 11232401.8489500
113724482.443058 8752405.80468670 113723146.577019 33730140.8917059 11206042.7918825
33889530.2639865 8752405.80468670 113722093.206969 33633939.6922064 11162100.5433850
11283801.1358007 8752405.80468670 113683482.563245 32619822.3286026 10824847.4001044
81851118.3437373 8752405.80468670 113673990.696232 32810467.8838717 10924632.1038267
18967522.4184325 8752405.80468670 113724334.213241 33846694.9387737 11258362.4998504
11166094.6694212 8752405.80468670 113716859.241903 33610572.4129988 11179156.6025225
12080807.8575974 8752405.80468670 113724445.283646 33868350.7431735 11269173.1510240
53040084.4667365 8752405.80468670 113716600.519447 33577505.3925039 11164687.8304165
1 件のコメント
Voss
2022 年 8 月 28 日
It seems likely that Bini(t) should be Bini(:,t) in both places and that QsL(t) should be QsL(:,t).
採用された回答
Chunru
2022 年 8 月 28 日
Looks like you need to specify time(t) to be different values insead of a constant.
q=[
0.000585366
0.015219512
0.100829268
0.153512195
0.211317073
];
c1=[2.913953437
0.357062085
15.85599407
2.345265863
0.46210313
8.900276197
0.916228389
0.464613769
0.50948815
3.625787133
];
c2=[0.381190238
2.378275189
0.145437759
0.373540574
2.071089271
0.197531521
0.777306452
1.590828583
1.401326121
0.381022168
];
c3=[1.357856932
1.393019098
1.239392127
1.740872069
1.921689678
1.041252003
0.974309699
0.516968399
1.098337754
0.636148757
];
c4=[1.634449245
1.455924213
1.172657972
1.114923556
0.459329589
0.263155864
1.640481459
0.547592137
1.999694643
0.589185378
];
ADP=2.37;
% time= [0.016666667
% 0.016666667
% 0.016666667
% 0.016666667
% 0.016666667
% ];
time = (0:4)/1000;
N = length(q);
M = length(c1);
QsL = zeros(M,N);
msL = zeros(M,N);
Bini=zeros (M,N);
for t=1:N
if t==1
Bini(:,t) = c1.*(1-exp(-ADP*c2))*24.6*10^6;
QsL(:,t) =c3.*q(t).^c4.*Bini(t);
msL(:,t)=QsL(t)*time(t);
else
Bini(:,t)=Bini(:,t)-msL(:,t-1);
QsL(:,t) =c3.*q(t).^c4.*Bini(t);
msL(:,t)=QsL(:,t)*time(t);
end
end
W_sim=QsL;
%Bini % it is different for each c1, .. c4
%whos
plot(time, Bini')
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!