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!