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

태그

질문:

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