Prob 4.12 Tutorial Engr/Math/Physics 25 Bruce Mayer, PE

advertisement
Engr/Math/Physics 25
Prob 4.12
Tutorial
Bruce Mayer, PE
Registered Electrical & Mechanical Engineer
BMayer@ChabotCollege.edu
Engineering/Math/Physics 25: Computational Methods
1
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Ballistic Trajectory
 Studied in Detail
in PHYS4A
 The Height, h, and
Velocity, v, as a
Fcn of time, t,
Launch Speed, v0,
& Launch Angle, A
ht   v0t sin A  gt 2 2
h
vt   v02  2v0 gt sin A  g 2t 2
A
t
Engineering/Math/Physics 25: Computational Methods
2
thit
t hit  2v0 g sin A
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Parametric Description
 For This Problem
a. h ~< 15 m

40 m/s
9.81 m/s2
h
30°
t
 Find TIMES for
Three cases
Engineering/Math/Physics 25: Computational Methods
3
Or Equivalently:
h  15m
b. [h ~< 15 m] &
[v ~> 36 m/s]

Or By DeMorgan’s
Theorem: ~([h 
15m] | [v  36 m/s])
c. [h < 5 m] I [v > 35
m/s]
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
1st Step → PLOT it
 Advice for Every Engineer and Applied
Mathematician or Physicist:
 Rule-1: When in
Doubt PLOT IT!
 Rule-2: If you don’t
KNOW when to DOUBT,
then PLOT EVERYTHING
Engineering/Math/Physics 25: Computational Methods
4
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
The Plot Plan
 The Plot Portion of the solution File
% Bruce Mayer, PE * 21Feb06
% ENGR25 * Problem 4-12
% file = Prob4_12_Ballistic_Trajectory.m
%
%
% INPUT PARAMETERS SECTION
A = 30*pi/180; % angle in radians
v0 = 40 % original velocity in m/S
g = 9.81 % Accel of gravity in m/sq-S
%
%
%CALCULATION SECTION
% calc landing time
t_hit = 2*v0*sin(A)/g;
% divide flite time into 100 equal intervals
t = [0: t_hit/100: t_hit];
% calc Height & Velocity Vectors as fcn of t
h = v0*t*sin(A) - 0.5*g*t.^2
v = sqrt(v0^2 - 2*v0*g*sin(A)*t + g^2*t.^2)
%
% plot h & v
%% MUST locate H & S Labels on plot before
script continues
plot(t,h,t,v), xlabel('Time (s)'),
ylabel('Height & Speed'), grid
Height & Speed
 Then the Plot
40
35
30
25
20
15
10
5
0
0
0.5
1
1.5
2
2.5
Time (s)
3
 Analyses Follow
Engineering/Math/Physics 25: Computational Methods
5
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
3.5
4
4.5
Analyze the Plots
 Draw HORIZONTAL or VERTICAL
Lines that Correspond to the
Constraint Criteria
 Where the Drawn-Lines Cross the
Plotted-Curve(s) Defines the BREAK
POINTS on the plots
 Cast DOWN or ACROSS to determine
Values for the Break-Points
 See Next Slide
Engineering/Math/Physics 25: Computational Methods
6
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
40
Speed
35
a) OK for : ht  ~ 15m [same as ht   15m]
30
25
20
Case a.
15
Height
10
Break-Pts
5
0.98
0
0
0.5
3.1
1
1.5
Engineering/Math/Physics 25: Computational Methods
7
2
2.5
Time (s)
3
3.5
4
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
4.5
40
Case b.
Speed
35
v Limits
b1) OK for : ht  ~ 15m AND vt  ~  36m / s
b2) OK for : ht   15m AND vt   36m / s
b3) OK for : ~ ht   15m OR vt   36m / s 
30
25
20
Height
15
10
5
1.1
0
0
0.5
1
1.5
Engineering/Math/Physics 25: Computational Methods
8
3.05
2
2.5
Time (s)
3
3.5
4
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
4.5
40
Case c.
Speed
35
v Limits
30
v Limits
c) OK for : ht   5m OR vt   35m / s
25
20
Height
15
10
5
1.49
0
0
0.5
1
1.5
Engineering/Math/Physics 25: Computational Methods
9
2.58
2
2.5
Time (s)
3
3.5
4
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
4.5
Advice on Using WHILE Loops
 When using Dynamically Terminated
Loops be SURE to Understand the
MEANING of the
• The LAST SUCEESSFUL
entry into the Loop
• The First Failure Which
Terminates the Loop
 Understanding First-Fail & Last-Success
helps to avoid “Fence Post Errors”
Engineering/Math/Physics 25: Computational Methods
10
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Solution Game Plan
 Calc t_hit
 Plot & Analyze to determine approx.
values for the times in question
• DONE
 Precisely Determine time-points
• For all cases
– Divide Flite-Time into 1000 intervals →
time row-vector with 1001 elements
– Calc 1001 element Row-Vectors h(t) & v(t)
Engineering/Math/Physics 25: Computational Methods
11
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Solution Game Plan cont.
 Case-a
• Use WHILE Loops to
– Count k-UP (in time) while h(k) < 15m
 Save every time ta_lo = h(k)
 The first value to fail corresponds to the value of ta_lo
for the Left-side Break-Point
– Count m-DOWN (in time) while h(m) < 15m
 Save every time ta_hi = h(m)
 The first value to fail corresponds to the value of ta_hi
for the Right-side Break-Point
Engineering/Math/Physics 25: Computational Methods
12
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Solution Game Plan cont.
ht  ~ 15m AND vt  ~ 36m / s  ~ ht   15m OR vt   36m / s
 Case-b → Same TACTICS as Case-a
• Use WHILE Loops to
– Count k-UP While h(k) < 15m OR v(k) > 36 m/s
 Save every time tb_lo = h(k) OR v(k)
 The Last Successful value of tb_lo is ONE index-unit LESS
than the Left Break point → add 1 to Index
 Find where [h<15 OR v>36] is NOT true
– Count m-DOWN While h(k) < 15m OR v(k) > 36 m/s
 Save every time tb_hi = h(m) OR v(m)
 The Last Successful value of tb_hi is ONE index-unit
MORE than the Right Break point → subtract 1 from index
 Find where [h<15 OR v>36] is NOT true
Engineering/Math/Physics 25: Computational Methods
13
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Solution Game Plan cont.
 Case-c → Same TACTICS as Case-b
• Use WHILE Loops to
– Count k-UP while h(k) < 5m OR v(k) > 35 m/s
 Save every time tc_lo = h(k) OR v(k)
 The Last Successful value of tc_lo IS the Left-side
Break-Point as the logical matches the criteria
– Count m-DOWN while
h(m) < 5m OR v(m) > 35 m/s
 Save every time tc_hi = h(m) OR v(k)
 The Last Successful value of tc_hi IS the Right-side
Break-Point as the logical matches the criteria
Engineering/Math/Physics 25: Computational Methods
14
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Solution Game Plan cont.
 MUST Properly LABEL the OutPut
using the Just Calculated BREAK-Pts
 Recall from the Analytical PLOTS
• Case-a is ONE interval (ConJoint Soln)
– ta_lo → ta_hi
• Case-b is ONE interval (ConJoint Soln)
– tb_lo → tb_hi
• Case-c is TWO intervals (DisJoint Soln)
– 0 → tc_lo
– tc_hi → t_hit
Engineering/Math/Physics 25: Computational Methods
15
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Alternate Soln → FIND
 Use FIND command along with a
LOGICAL test to locate the INDICES of
h associated with the Break Points
• LOWEST index is the Left-Break
• HIGHEST Index is the Right-Break
 Same Tactics for 3 Sets of BreakPts
• Again, MUST label Properly
• Must INcrement or DEcrement “found”
indices to match logical criteria
– Need depends on Logical Expression Used
Engineering/Math/Physics 25: Computational Methods
16
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Compare: WHILE vs FIND
 Examine Script files
• Prob4_12_Ballistic_Trajectory_by_WHILE_1209.m
• Prob4_12_Ballistic_Trajectory_by_FIND_1209.m
 FIND is Definitely More COMPACT
(fewer KeyStrokes)
 WHILE-Counter is More INTUITIVE → Better
for someone who does not think in “Array
Indices”
Engineering/Math/Physics 25: Computational Methods
17
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Compare: WHILE vs FIND
 While vs Find; Which is Best?
 The “best” one is the one that
WORKS in the
SHORTEST
amount of YOUR
TOTAL-TIME
Engineering/Math/Physics 25: Computational Methods
18
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
% Bruce Mayer, PE * 21Feb06 * Rev. 22Feb09
Portion of The m-file
% ENGR25 * Problem 4-12
% file = Prob4_12_Ballistic_Trajectory.m
%
% INPUT PARAMETERS SECTION
A = 30*pi/180; % angle in radians
v0 = 40; % original velocity in m/S
g = 9.81; % Accel of gravity in m/sq-S
%
%
%CALCULATION SECTION
% calc landing time
t_hit = 2*v0*sin(A)/g;
display('The Flite Time in sec:')
disp(t_hit)
% divide flite time in 1000 equal intervals
t = [0: t_hit/1000: t_hit];
% 2X check no. of elements in vector t
Elements_in_t = length(t)
% calc Height & Velcity Vectors as fcn of t
h = v0*t*sin(A) - 0.5*g*t.^2;
v = sqrt(v0^2 - 2*v0*g*sin(A)*t + g^2*t.^2);
Engineering/Math/Physics 25: Computational Methods
19
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
FOLLOWING ARE FOR
PROJECTION ONTO
WHITEBOARD
Engineering/Math/Physics 25: Computational Methods
20
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
ENGR25 P4-12 * h15 & v36
40
35
Height & Speed
30
25
20
15
10
5
0
Engineering/Math/Physics 25: Computational Methods
21
0
0.5
1
1.5
2
Time (s)
2.5
3
Bruce Mayer, PE
3.5
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
4
ENGR25 P4-12 * h5 & v35
40
35
Height & Speed
30
25
20
15
10
5
0
Engineering/Math/Physics 25: Computational Methods
22
0
0.5
1
1.5
2
2.5
3 Bruce Mayer,
3.5PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Time (s)
4
Engineering/Math/Physics 25: Computational Methods
23
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Programming-1.ppt
Portion of Plot m-file
% Bruce Mayer, PE * 20Feb13
% ENGR25 * Problem 4-12 Constraint Plots
% file = Prob4_12_Ballistic_Trajectory_Constraint_Plots_1302.m
%
% INPUT PARAMETERS SECTION
A = 30*pi/180; % angle in radians
v0 = 40; % original velocity in m/S
g = 9.81; % Accel of gravity in m/sq-S
disp(' ')
disp('Locate Break Points by FIND command')
%
%CALCULATION SECTION
% calc landing time
t_hit = 2*v0*sin(A)/g;
display('The Flite Time in sec:')
disp(t_hit)
% divide flite time in 1000 equal intervals
t = [0: t_hit/1000: t_hit];
% 2X check no. of elements in vector t
Elements_in_t = length(t)
% calc Height & Velcity Vectors as fcn of t
h = v0*t*sin(A) - 0.5*g*t.^2;
v = sqrt(v0^2 - 2*v0*g*sin(A)*t + g^2*t.^2);
%
% plot h & v constraints: h15 & v36
tln = [0 4.1]; h15 = [15, 15]; v36 = [36,36]
plot(t,h,t,v, tln,h15, tln, v36, 'linewidth', 2), xlabel('Time
(s)'),...
ylabel('Height & Speed'), grid, title('ENGR25 P4-12 * h15 &
v36'),...
axis([0 4.1 0 40])
display('showing h15 & v36 plot -- Hit Any Key to Continue')
pause
Download