I can solve this problem by those code but how can i solve this problem by using loop?

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)

回答(1 个)

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 个评论

Sorry for not clarify the question clearly , what i really want to ask is how to determine the peak elevation altitude and it coressponding time by using while loop instead of using max function
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;

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

版本

R2021b

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by