i ask about if statement and loop
Mostrar comentarios más antiguos
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 comentarios
the cyclist
el 21 de Mayo de 2022
Editada: the cyclist
el 21 de Mayo de 2022
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
el 21 de Mayo de 2022
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
el 21 de Mayo de 2022
Editada: Fangjun Jiang
el 21 de Mayo de 2022
laziest question yet hard working answers. What is the question?
Respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!