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...

1 Ansicht (letzte 30 Tage)
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

Antworten (1)

Wayne King
Wayne King am 18 Sep. 2012
Bearbeitet: Wayne King am 18 Sep. 2012
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

Kategorien

Mehr zu Condensed Matter & Materials Physics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by