Most recent value incremented variable from 'while' loop
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Riley Schmitt
il 9 Dic 2020
Risposto: Walter Roberson
il 10 Dic 2020
This code is meant to determine how low a cone will sink in water before the buoyancy force is equal to the weight of the cone. The buoyancy force is determined by summing the force on each area element and increasing the depth (increases the pressure) until the buoyancy force is equal to the weight of the cone. My code seems to be running ok as my while loop terminates when my "sumFz" is lower but similar in size to "'wCo", but when I go to retrieve the last 'z' (the depth) it just says it's zero. Can someone figure out why, please?
rhoFluid = 1000;
beta = 30*pi/180;
dtheta = pi/50;
mCo = 15;
wCo = g*mCo %Weight of cone
N = 100;
h = 0.5;
dz = h/N;
sumFz = wCo+1;
z = 0;
while sumFz <= wCo
pressure = rhoFluid*g*z;
for j = 1:N
r = z*tan(beta);
Fz(j) = pressure*1/2*r^2*dtheta*dz*cos(beta);
end
sumFz = sum(Fz,'all') %Total buoancy force at current depth
z = z+dz;
end
sum(Fz,'all')
z
0 Commenti
Risposta accettata
Walter Roberson
il 10 Dic 2020
sumFz = wCo+1;
You initialize sumFz to be greater than wCo
while sumFz <= wCo
but your while only happens when sumFz is less than (or equal to) wCo . Which it never is, because you initialized it to be greater than.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Language Fundamentals in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!