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
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
2022년 2월 12일
David Hill
2022년 2월 12일
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!