Prob 9-28 Solution Tutorial Engineering 25

advertisement
Engineering 25
Prob 9-28
Solution
Tutorial
Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
BMayer@ChabotCollege.edu
Engineering-25: Computational Methods
1
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
Prob 9-28
Ref Example 9.3-3
Engineering-25: Computational Methods
2
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
Prob 9-28
Engineering-25: Computational Methods
3
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
Prob 9-28
Engineering-25: Computational Methods
4
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
Prob 9-28
Engineering-25: Computational Methods
5
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
Prob 9-28
Engineering-25: Computational Methods
6
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
The MATLAB Code
% Bruce Mayer, PE * 17Apr12
% ENGR25 * problem 9.28
% file = Prob9_28_Tank_Draining_Soln_1204.m
% use with function SphereTank.m
%
% Ref Example 9.3-3
%
clear
% clears memory
%
% Put in Constants
r = 3; % tank radius in meters
A = pi*0.02^2; % Outlet Area in sq-m
Cd = 0.5; % Outlet drag coefficient
h0 = 5; % initial (time-zero) liquid hgt
g = 9.81; % acceleration of gravity in m/s^2
%
% Ask User for Top and MidLevel
htop = input('Tank TopLevel in m = ')
%
% Calc max dh_dt Using Top Level Estimate
dh_dt = -Cd*A*sqrt(2*g*htop)/(pi*(2*r*htop-htop^2))
%
% Calc estimated Minimun Drain Time
tdrain = -htop/dh_dt;
%
% display estimated drain time
disp('Esimated Drain Time in Sec = ')
disp(tdrain)
%
% Pause for 5 seconds
pause(5)
%
% use ode45 solver with tdrain to find first-cut Solution
[t, h] = ode45('SphereTank', [0, tdrain], htop);
%
% Use While Loop to ask user to iterate on tdrain until 1% accurate
% need to use ABS in case ODE45 returns a complex number for the last
value
% in solution vector h
Engineering-25: Computational Methods
7
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
The MATLAB Code
while abs(h(length(h)))/htop > 0.01
[t, h] = ode45('SphereTank', [0, tdrain], htop);
% test for COMPLEX, and hence invalid, Results
if imag(h(length(h)))~= 0
disp('estimated drain time is too LONG; REDUCE the value and
try again')
tdrain = input('input REDUCED estimate for drain time = ')
else
plot(t/1000,h),xlabel('t (k-sec)'), ylabel(' h (feet)'),
grid, axis([0 1.5*tdrain/1000 -0.1*htop htop])
tdrain = input('based on last plot input INCREASED estimate
for drain time = ')
end
end
%
% calc drain time in hours
td_hrs = t(length(t))/3600;
disp('Drain time in hours = ')
disp(td_hrs)
disp('height at this drain time in m = ')
disp(h(length(h)))
%
% The SOLUTION Plot
plot(t/1000,h),xlabel('t (k-sec)'), ylabel(' h (feet)'), grid,
title('Solution to P9.28')
%
disp('Showing h(t) plot - Hit any Key to Continue')
pause
Engineering-25: Computational Methods
8
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
The MATLAB Code
% just for Fun Calc [dh/dt](t) by Central Difference
disp('Ready to Plot dh/dt as fcn of t - Hit any Key to Continue')
pause
%
nmax = length(t)
m = 0
for k = 2:(nmax-1)
delh = h(k+1) - h(k-1);
delt = (t(k+1) - t(k-1))/1000; % delt units to be k-sec
m = m+1;
dhdt(m) = delh/delt;
t_dhdt(m) = ((t(k+1)+t(k-1))/2)/1000; % the avg of times used for
delt in kSec
end
plot(t_dhdt, dhdt),xlabel('t (k-sec)'), ylabel(' dh/dt (feet/kSec)'),
grid,...
title('P9.28 dh/dt by Central Difference')
The SphereTank Function
function dhdt = SphereTank(t,h);
% Bruce Mayer, PE * 18Apr12
% ENGR25 * Problem 9-28
%
% Derivative Function for use ODE45 solver
dhdt = -2e-4*sqrt(19.62*h)/(6*h-h^2);
Engineering-25: Computational Methods
9
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
h(t) Result
Solution to P8.24
5
4.5
4
h (feet)
3.5
3
2.5
2
1.5
1
0.5
0
0
5
10
15
20
25
t (k-sec)
 Slope looks about Constant
over about 5-20 kSec
Engineering-25: Computational Methods
10
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
30
dh/dt by Central Diff
P8.24 dh/dt by Central Difference
-0.1
-0.2
dh/dt (feet/kSec)
-0.3
h = 2.5 ft at
about 12 kSec
-0.4
-0.5
-0.6
-0.7
-0.8
-0.9
0
5
10
15
t (k-sec)
20
25
 Slope are quite close to
those Calculated on Paper
• Slope near t = 0 is about -3.9
• Slope near h = 2.5’ is
about -1.6
Engineering-25: Computational Methods
11
Bruce Mayer, PE
ENGR-25_Prob_8-24_Solution.ppt
30
Download