I can solve this problem by those code but how can i solve this problem by using loop?
Afficher commentaires plus anciens


error = 1;
while error
mukim = input('Please select mukim (A = Pulai, B = Tebrau, C = Kota Tinggi): ','s');
switch mukim
case 'A'
v = 45;
error = 0;
case 'B'
v = 55;
error = 0;
case 'C'
v = 50;
error = 0;
otherwise
fprintf('\n Wrong selection, please type A, B or C \n\n')
end
end
h = input ('Chimney height (meter) from the earth surface: ');
t = 0;
i=1:100;
t=t+i;
z = h + (80/15)*(v + ((80*9.81)/15))*(1-exp((-15/80)*t))-(((80*9.81)/15)*t);
[maxz,correspondindtimeforz]=max(z);
maxtime=t(correspondindtimeforz);
fprintf('\nThe particles achieve peak elevation altitude = %5.2f meter after %i seconds release from chimney.\n\n', maxz, maxtime)
Réponses (1)
David Hill
le 11 Fév 2022
Don't understand your question. You are using a loop.
l=[45 55 50];
while 1
mukim = input('Please select mukim (A = Pulai, B = Tebrau, C = Kota Tinggi): ','s');
if ismember(mukim,'ABC')
v=l(ismember('ABC',mukim));
break;
end
fprintf('\n Wrong selection, please type A, B or C \n\n');
end
2 commentaires
CHEE KIN CHUM
le 12 Fév 2022
David Hill
le 12 Fév 2022
Just need to do some math.
l=[45 55 50];
while 1
mukim = input('Please select mukim (A = Pulai, B = Tebrau, C = Kota Tinggi): ','s');
if ismember(mukim,'ABC')
v=l(ismember('ABC',mukim));
break;
end
fprintf('\n Wrong selection, please type A, B or C \n\n');
end
h = input ('Chimney height (meter) from the earth surface: ');
c = 15;
g = 9.81;
w = 80;
tmax = w/c*log((v*c+w*g)/w/g);%seting derivative == 0 and solving for t
zmax = h + (w/c)*(v + w*g/c)*(1-exp(-c/w*tmax))-w*g/c*tmax;
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!