how to do if and else statement for this equation
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
shagun chaudhary
el 24 de Ag. de 2022
Hi,
I ma trying to do if and else stituation for my code. I dont what is the proble. I should get my answer as Wsim= [10X5]. can please somebody help? it is important. I will be extremely grateful.
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);
QsL = zeros(N,1);
msL = zeros(N,1);
for t=1:N
if t==1
Bini = c1*(1-exp(-ADP*c2))*24.6*10^6;
QsL(t) =c3*q(t)^c4*Bini;
msL(t)=QsL(t)*time(t);
else
Bini=Bini-msL(t-1);
QsL(t) =c3*q(t)^c4*Bini;
msL(t)=QsL(t)*time(t);
end
end
W_sim=QsL;
0 comentarios
Respuesta aceptada
Torsten
el 24 de Ag. de 2022
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);
for t=1:N
if t==1
Bini = c1.*(1-exp(-ADP*c2))*24.6*10^6;
QsL(:,t) =c3.*q(t).^c4.*Bini;
msL(:,t)=QsL(t)*time(t);
else
Bini=Bini-msL(:,t-1);
QsL(:,t) =c3.*q(t).^c4.*Bini;
msL(:,t)=QsL(:,t)*time(t);
end
end
W_sim=QsL
8 comentarios
Torsten
el 27 de Ag. de 2022
Editada: Torsten
el 27 de Ag. de 2022
can you please help me to get the code where Bin has alssame matrix as qsl and msl.
You can do this, but it won't change the result:
q=[0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0.000585366
0.015219512
0.100829268
0.153512195
0.211317073
0.272780488
0.335121951
0.47795122
0.619317073
0.70404878
0.838829268
0.95604878
1.028926829
1.102097561
1.133414634
1.186536585
1.175853659
1.180390244
1.153609756
1.210390244
1.199121951
1.186390244
1.214780488
1.164
1.154195122
1.162829268
1.150390244
1.160780488
1.193414634
1.192829268
1.192536585
1.191512195
1.268195122
1.319268293
1.345609756
1.344731707
1.390536585
1.436341463
1.481853659
1.531463415
1.421268293
1.364634146
1.362146341
1.303463415
1.283707317
1.191073171
1.208341463
1.117317073
1.041365854
1.026585366
1.022926829
0.949902439
0.922243902
0.904829268
0.852585366
0.832390244
0.83195122
0.78995122
0.793756098
0.769463415
0.759219512
0.73404878
0.704195122
0.735804878
0.714146341
0.718390244
0.646829268
0.675512195
0.646390244
0.628097561
0.642146341
0.612
0.571317073
0.54497561
0.51702439
0.498585366
0.450731707
0.443268293
0.41604878
0.380195122
0.374341463
0.346097561
0.322390244
0.306146341
0.272780488
0.260487805
0.236487805
0.220390244
0.211317073
0.196536585
0.186439024
0.176634146
0.163317073
0.151756098
0.143121951
0.12995122
0.12204878
0.115463415
0.108878049
0.103170732
0.096439024
0.091463415
0.086634146
0.078146341
0.075804878
0.07404878
0.067317073
0.034243902
0.03204878
0.022243902
0.020926829
0.019902439
0.01902439
0.018
0.007317073
0.009219512
0.007170732
0.006731707
0.004097561
0.004243902
0.004097561
0.004682927
0.004536585
0.004243902
0.004097561
0.00395122
0.004682927
0.004390244
0.004243902
0.004682927
0.004536585
0.004390244
0.003365854
0.004243902
0.004097561
0.002634146
0.002634146
0.002487805
0.002341463
0.002341463
0.002195122
0.00204878
0.00204878
0.001902439
0.001902439
0.001756098
0.001756098
0.001756098
0.001756098
0.001756098
0.001609756
0.001609756
0.001609756
0.001463415
0.001463415
0.001463415
0.001463415
0.001317073
0.001317073
0.001317073
0.001317073
0.001317073
0.001317073
0.001170732
0.001170732
0.001170732
0.001170732
0.001170732
0.001170732
0.001170732
0.00102439
0.00102439
0.00102439
0.00102439
0.00102439
0.000878049
0.000878049
0.000878049
0.000878049
0.000878049
0.000878049
0.000878049
0.000878049
0.000878049
0.000731707
0.000878049
0.000731707
0.000731707
0.000731707
0.000731707
0.000731707
0.000731707
0.000731707
0.000731707
0.000731707
0.000731707
0.000731707
0.000585366
0.000585366
0.000585366
0.000585366
0.000585366
0.000585366
0.000585366
0.000585366
0.000585366];
c1=[9.96758922769766
21.7863553786390];
c2=[1.07087547298308
4.59298875702875];
c3=[0.659036959801163
0.350587816233283];
c4=[1.35390855987385
0.572921003882392];
ADP=2.37;
time= [0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
0.016666667
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-1)-msL(:,t-1);
QsL(:,t) =c3.*(q(t).^c4).*Bini(:,t);
msL(:,t)=QsL(:,t).*time(t);
end
end
W_sim=QsL;
for i=1:24
W_sim(:,10*(i-1)+1:10*i)
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!