Need a to plot a graph
Afficher commentaires plus anciens
close all; clear;
h = input('height of water in tank = ');
H1 = 11; %in
H2 = 5; %in m
r1 = 3.5; %in m
r2 = 6; %in m
if h < 0
Vtotal = 0;
elseif h < 11
Vtotal = pi*r1*r1*h; % Volume of water in tank in m^3
else
rh = r1+((h-H1)*(r2-r1))/H2;
Vtotal = pi*r1*r1*H1+(pi*(h-H1)*(r1*r1+r1*rh+rh*rh))/3; % Volume of water in tank in m^3
end
plot(h,Vtotal)
I dont know how to plot the graph from h = 0 to 17. I am just not sure what needs to be changed in the code. Thank you
1 commentaire
Réponses (2)
hvals = linspace(0,17);
numh = length(hvals);
Vtotal = zeros(numh, 1);
H1 = 11; %in
H2 = 5; %in m
r1 = 3.5; %in m
r2 = 6; %in m
for hidx = 1 : numh
h = hvals(hidx);
if h < 0
Vtotal(hidx) = 0;
elseif h < 11
Vtotal(hidx) = pi*r1*r1*h; % Volume of water in tank in m^3
else
rh = r1+((h-H1)*(r2-r1))/H2;
Vtotal(hidx) = pi*r1*r1*H1+(pi*(h-H1)*(r1*r1+r1*rh+rh*rh))/3; % Volume of water in tank in m^3
end
end
plot(hvals,Vtotal)
Michael Habermann
le 25 Jan 2023
Modifié(e) : Michael Habermann
le 25 Jan 2023
close all; clear;
H1 = 11; %in
H2 = 5; %in m
r1 = 3.5; %in m
r2 = 6; %in m
h_low = 0:11
Vtotal_low = pi*r1*r1*h_low % Volume of water in tank in m^3
h_high = 12:17
rh = r1+((h_high-H1).*(r2-r1))./H2
Vtotal_high = pi*r1*r1*H1+(pi.*(h_high-H1).*(r1*r1+r1.*rh+rh.*rh))/3 % Volume of water in tank in m^3
h = [h_low, h_high]
Vtotal = [Vtotal_low, Vtotal_high]
plot(h,Vtotal)
Catégories
En savoir plus sur Vector Volume Data dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

