i ask about if statement and loop
古いコメントを表示
for H2=256.5:1:269.3
for Hs=250:1:256
for p3=675:1:900
for pm=670:1:674
for vm=0.0008299:0.0008581
ms=(As*(2*0.95*(H2-Hs))^0.5)/((2*0.95*(H2-Hs))^0.5);
Vs=(2*0.95*(H2-Hs))^0.5;
mm=mp+ms;
Vm=mp/Am;
muo=(ms/mp);
Vbs=((Vp+muo*Vs)/((muo+1)*(1+(0.03*80)/(2*20))))+(((p3+pm)*Am)/((1+(0.03*80))*mm));
Hbs=((Hp+((vp^2)/2)+muo*(Hs+((Vs^2)/2)))/(1+muo))-((Vm^2)/2);
mmm=(Vm*Am)/vm;
if mmm==mm
Vs=~0;
return
else
break
end
end
end
end
end
end
4 件のコメント
the cyclist
2022 年 5 月 21 日
編集済み: the cyclist
2022 年 5 月 21 日
We can't run your code without defining the constants. If I just arbitrarily set all the undefined constants to 1, your code runs to completion.
So, what is your question?
Walter Roberson
2022 年 5 月 21 日
for vm=0.0008299:0.0008581
default increment is 1 so that line will only include the lower bound.
for H2=256.5:1:269.3
for Hs=250:1:256
ms=(As*(2*0.95*(H2-Hs))^0.5)/((2*0.95*(H2-Hs))^0.5);
Vs=(2*0.95*(H2-Hs))^0.5;
mm=mp+ms;
Vm=mp/Am;
muo=(ms/mp);
for p3=675:1:900
for pm=670:1:674
for vm=0.0008299:0.0008581
Vbs=((Vp+muo*Vs)/((muo+1)*(1+(0.03*80)/(2*20))))+(((p3+pm)*Am)/((1+(0.03*80))*mm));
Hbs=((Hp+((vp^2)/2)+muo*(Hs+((Vs^2)/2)))/(1+muo))-((Vm^2)/2);
mmm=(Vm*Am)/vm;
if mmm==mm
...
moving what is invariant to the inner loop variables out for efficiency.
Also NB: that
ms=(As*(2*0.95*(H2-Hs))^0.5)/((2*0.95*(H2-Hs))^0.5);
Vs=(2*0.95*(H2-Hs))^0.5;
can be written more simply/efficiently as
Vs=sqrt(2*0.95*(H2-Hs));
ms=As*Vs/Vs;
which shows that ms is invariant and ==> As as the other factors cancel identically.
A sample case illustrates numerically...
>> As=pi; H2=256;Hs=250;
>> ms=(As*(2*0.95*(H2-Hs))^0.5)/((2*0.95*(H2-Hs))^0.5)
ms =
3.1416
>>
As originally coded, the answer for the example is identically pi, the value set for As and is constant.
One would presume this is probably not what was intended...
Fangjun Jiang
2022 年 5 月 21 日
編集済み: Fangjun Jiang
2022 年 5 月 21 日
laziest question yet hard working answers. What is the question?
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!