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 件)

David Hill
David Hill 2022 年 2 月 11 日
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 件のコメント

CHEE KIN CHUM
CHEE KIN CHUM 2022 年 2 月 12 日
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 ExchangeResizing and Reshaping Matrices についてさらに検索

製品

リリース

R2021b

タグ

質問済み:

2022 年 2 月 11 日

コメント済み:

2022 年 2 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by