it won't run as it keeps showing illegal use of the word else

1 visualización (últimos 30 días)
Eti Rastogi
Eti Rastogi el 14 de Sept. de 2020
Respondida: Ayush Gupta el 17 de Sept. de 2020
tank_diameter = 4.1; % Diameter of the tank [meters]
total_tank_length = 20.5; % total length of the tank [meters]
fluid_height_increment = 0.25; % increments for fluid height [meters]
safety_percent = 0.8; % safety percent [decimal]
%% ____________________
%% CALCULATIONS
tank_radius = tank_diameter/2; % finding tank radius
Length_cylindrical_section = (total_tank_length - (2*tank_radius)); % finding length of cylindrical section
% using variables A, B and C to calculate the total tank volume
A = ((pi*(tank_diameter)^2) *((3*tank_radius) - tank_diameter)/3);
B = ((tank_radius)^2) * (acos((tank_radius -tank_diameter)/tank_radius));
C = (tank_radius) - (tank_diameter)*(sqrt((2*tank_radius*tank_diameter)- (tank_diameter)^2));
tank_volume = A+Length_cylindrical_section*(B-C);
% using fluid heights to find total volume tolerance
fluid_height1 = tank_radius + (0.5*fluid_height_increment);
fluid_height2 = tank_radius - (0.5*fluid_height_increment);
v_tol = (tank_volume * (fluid_height1)) - (tank_volume * (fluid_height2));
for fluid_height = 0
A = ((pi*(fluid_height)^2) *((3*tank_radius) - fluid_height)/3);
B = ((tank_radius)^2) * (acos((tank_radius - fluid_height)/tank_radius));
C = (tank_radius) - (fluid_height)*(sqrt((2*tank_radius*fluid_height)- (fluid_height)^2));
fluid_volume = A+Length_cylindrical_section*(B-C);
fluid_height1 = tank_radius + (0.5*fluid_height_increment);
fluid_height2 = tank_radius - (0.5*fluid_height_increment);
v_tol = (fluid_volume * (fluid_height1)) - (fluid_volume * (fluid_height2));
Number_loops =0;
while fluid_volume <= (tank_volume - v_tol )
Fluid_height = fluid_height + fluid_height_increment;
Number_loops = Number_loops +1;
else Number_loops = Number_loops +1;
fprintf('The final fluid volume is %.2f m^3. /n' , fluid_volume);
end
disp('The number of iterations are %.0f' , Number_loops);
disp('The safe fill volume is %.2f m^3.' , v_tol);
disp('The final fluid volume is %.2f m^3.' , fluid_volume);
plot (fluid_volume ,fluid_height);
xlabel = 'Fluid Height [m]';
ylabel = 'Fluid Volume [m^3]' ;
title = ' Fluid Volume vs Fluid Height';
end
  3 comentarios
Rik
Rik el 14 de Sept. de 2020
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
Eti Rastogi
Eti Rastogi el 14 de Sept. de 2020
sorry about that and thank u

Iniciar sesión para comentar.

Respuestas (1)

Ayush Gupta
Ayush Gupta el 17 de Sept. de 2020
The problem here is with the syntax of while loop, where else is being used inside while loop without using if first. Read about the documentation of while loop and how to use it, here. Refer to the following code on the changes to make:
while fluid_volume <= (tank_volume - v_tol )
Fluid_height = fluid_height + fluid_height_increment;
Number_loops = Number_loops +1;
%else Number_loops = Number_loops +1;
%fprintf('The final fluid volume is %.2f m^3. /n' , fluid_volume);
end

Categorías

Más información sobre Fluid Dynamics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by