What syntax can I use, say, in the calculation of the number of tanks of a plant where the length of each tank should not be greater than 50? Below is the code I tried...
조회 수: 3 (최근 30일)
이전 댓글 표시
while length > 50
lbratio= input('\nEnter length/breadth ratio: ');
vol = ret_time/24 * q;
area = q/ofr;
breadth = sqrt(area/lbratio);
length = lbratio*breadth;
depth = vol/area;
fprintf(1,'Data :\n');
fprintf(1,'Volume is %10.5f\n', vol);
fprintf(1,'Area is %10.5f\n', area);
fprintf(1,'length is %10.5f\n', length);
fprintf(1,'breadth is %10.5f\n', breadth);
fprintf(1,'depth is %10.5f\n', depth);
fprintf(1,'length/breadth ratio is %10.5f', lbratio);
end
댓글 수: 0
답변 (1개)
Wayne King
2012년 9월 18일
편집: Wayne King
2012년 9월 18일
length is a MATLAB function so you should try to avoid using variable names that are the same as MATLAB function names. area is also a MATLAB function. Further, your post says the length should not be greater than 50, but your while loop condition is while length > 50
In your example you give us no idea what a reasonable starting value for the values of a number of variables so I'm not sure how you expected anyone to help you. Here I have just assigned arbitrary values to get it the loop to work.
I've also changed the while condition to be length less than or equal to 50 -- I've renamed length to len and I've renamed area to ar.
len = 0;
ret_time = 0;
q = 1;
ofr = 1;
while len <= 50
lbratio= input('\nEnter length/breadth ratio: ');
vol = ret_time/24 * q;
ar = q/ofr;
breadth = sqrt(ar/lbratio);
len = lbratio*breadth;
depth = vol/ar;
fprintf(1,'Data :\n');
fprintf(1,'Volume is %10.5f\n', vol);
fprintf(1,'Area is %10.5f\n', ar);
fprintf(1,'length is %10.5f\n', len);
fprintf(1,'breadth is %10.5f\n', breadth);
fprintf(1,'depth is %10.5f\n', depth);
fprintf(1,'length/breadth ratio is %10.5f\n', lbratio);
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Condensed Matter & Materials Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!