Need a to plot a graph

조회 수: 1 (최근 30일)
Julia Sabetti
Julia Sabetti 2023년 1월 25일
편집: Torsten 2023년 1월 25일
close all; clear;
h = input('height of water in tank = ');
Unable to run the 'fevalJSON' function because it calls the 'input' function, which is not supported for this product offering.
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
Torsten
Torsten 2023년 1월 25일
편집: Torsten 2023년 1월 25일
So the tank is a cylinder with radius r1 for 0 <= h <= H1, followed by a frustrum of height H2 with lower radius r1 and upper radius r2 ?
Then you still have to distinguish the cases h <= H1 + H2 and h > H1 + H2.

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2023년 1월 25일
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
Michael Habermann 2023년 1월 25일
편집: Michael Habermann 2023년 1월 25일
close all; clear;
H1 = 11; %in
H2 = 5; %in m
r1 = 3.5; %in m
r2 = 6; %in m
h_low = 0:11
h_low = 1×12
0 1 2 3 4 5 6 7 8 9 10 11
Vtotal_low = pi*r1*r1*h_low % Volume of water in tank in m^3
Vtotal_low = 1×12
0 38.4845 76.9690 115.4535 153.9380 192.4226 230.9071 269.3916 307.8761 346.3606 384.8451 423.3296
h_high = 12:17
h_high = 1×6
12 13 14 15 16 17
rh = r1+((h_high-H1).*(r2-r1))./H2
rh = 1×6
4.0000 4.5000 5.0000 5.5000 6.0000 6.5000
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
Vtotal_high = 1×6
467.5737 524.3842 595.3318 681.9874 785.9218 908.7057
h = [h_low, h_high]
h = 1×18
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Vtotal = [Vtotal_low, Vtotal_high]
Vtotal = 1×18
0 38.4845 76.9690 115.4535 153.9380 192.4226 230.9071 269.3916 307.8761 346.3606 384.8451 423.3296 467.5737 524.3842 595.3318 681.9874 785.9218 908.7057
plot(h,Vtotal)

카테고리

Help CenterFile Exchange에서 Chemistry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by