Chp9: Integration & Differentiation Engr/Math/Physics 25 Bruce Mayer, PE

advertisement
Engr/Math/Physics 25
Chp9: Integration
& Differentiation
Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
BMayer@ChabotCollege.edu
Engineering/Math/Physics 25: Computational Methods
1
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Learning Goals
 Demonstrate Geometrically the
Concepts of Numerical Integ. & Diff.
• Integrals → Trapezoidal, Simpson’s, and
Higher-order rules
• Derivative → Finite Difference Methods
 Use MATLAB to Numerically Evaluate
Math/Data Integrals
 Use MATLAB to Numerically Evaluate
Math/Data Derivatives
Engineering/Math/Physics 25: Computational Methods
2
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Why Differentiate, Integrate?
 We encounter differentiation and integration
on a Daily Basis
 Differentiation: Many Important Physical
processes/phenomena are best Described in
Derivative form; Some Examples
• Newton’s 2nd Law:
F  d mv dt
• Heat Flux:
q  k  dT dx 
• Drag on a Parachute:
dv dt  mg  cv  m
• Capacitor Current:
i  C dV dt 
Engineering/Math/Physics 25: Computational Methods
3
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Why Differentiate, Integrate?
 Integration: Integration is commonplace in
Science and Engineering
Calculation of
Geographic Areas
River Channel
Cross Section
Engineering/Math/Physics 25: Computational Methods
4
Wind-Force
Loading
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Review: Integration
 Integration: the area
under the curve
described by the
function f(x) with
respect to the
independent variable
x, evaluated
between the limits
x = a to x = b.
A
A   f x dx
b
a
Engineering/Math/Physics 25: Computational Methods
5
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Review: Differentiation
 Differentiation: rate of change of a dependent
variable with respect to an independent variable.
dy
dx
x  xi
f xi  x   f xi 
y
 Lim
 Lim
x 0 x x 0
x
Engineering/Math/Physics 25: Computational Methods
6
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Integral Properties
 Indefinite Intregral
w/ Variable End-Pts
 Piecewise Property
y
yx    g x dx  f x   Const
 Initial/Final Value
Formulations
yt    g x dx  f t   y0
t
x
a
c
a
c
a
b
c
 Linearity → for
t
Constants p & q
y t    g x dx  f t   y    b

0

y t    g x dx  y    f t 
t
Engineering/Math/Physics 25: Computational Methods
7
b
 f xdx  f xdx   f xdx
b
  p  f x   q  g x dx 
a
p  f x dx q  g x dx
b
b
a
aBruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Derivative Properties
 PRODUCT Rule
• Given
yx   f x   g x 
• Then
dy
dg
df
 f x   g x 
dx
dx
dx
Engineering/Math/Physics 25: Computational Methods
8
 QUOTIENT Rule
• Given


f
x
yx  
g x 
• Then
df
dg
g x   f x 
dy
dx
dx

2
dx
g x 
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Alternative Quotient Rule
 Restate Quotient as rational Exponent,
then apply
f x 
1
 f x g x 
Product rule; y  x  
g x 
to whit:
 Then dy  f  x  1g  x  2 dg  g  x 1 df
dx
dx
dx
 Putting 2nd term over common denom
dg
df
 f x 
g x 
dy
dx 
dx

2
2
dx
g x 
g x 
Engineering/Math/Physics 25: Computational Methods
9
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Why Numerical Methods?
 Numerical Integration
•
•
Engineering/Math/Physics 25: Computational Methods
10
Very often, the function
f(x) to differentiate, or the
integrand to integrate, is
TOO COMPLEX to yield
exact analytical solutions.
In most cases in
engineering testing, the
function f(x) is only
available in a
TABULATED form with
values known only at
DISCRETE POINTS
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Numerical Integration
 Game Plan: Divide
Unknown Area into
Strips (or boxes),
and Add Up
 To Improve
Accuracy the TOP of
the Strip can Be
• Slanted Lines
– Trapezoidal Rule
• Parabolas
– Simpson’s Rule
• Higher Order
PolyNomials
Engineering/Math/Physics 25: Computational Methods
11
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Strip-Top Effect
 Trapezoidal Form
 Parabolic
(Simpson’s) Form
• Higher-Order-Polynomial Tops Lead to increased,
but diminishing, accuracy.
Engineering/Math/Physics 25: Computational Methods
12
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Strip-Count Effect
10 Strips
20 Strips
 Adaptive Integration → INCREASE the stripCount in Regions with Large SLOPES
• More Strips of Constant
Width Tends to work
just as well
Engineering/Math/Physics 25: Computational Methods
13
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
dy/dx by Finite Difference Approx.
y(x)
y(x-Δx)
dy y
 Derivative at Point-x : m 

dx x
• Forward Difference
y yx  x   yx  yx  x   yx 
m fwd 


x  x   x
x
x
y(x)
y(x+Δx)
Engineering/Math/Physics 25: Computational Methods
14
• Backward Difference
y y  x   y x  x 
mbkwd

x
x  x  x 
y x   y  x  x 
y(x)

x
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
dy/dx by Finite Difference Approx.
y(x)
y(x-Δx)
 Central Difference = Average of
fwd and bkwd Slopes :
mcent  m fwd  mbkwd  2
y(x)
y(x+Δx)
Engineering/Math/Physics 25: Computational Methods
15
1  y x  x   y  x  y  x   y  x  x  
 


2
x
x

y x  x   y x  x 

2x
y(x)
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
dy/dx by Discrete-Point Difference
 From Previous LET
x  x  xn 1
x  xn
y  y  yn 1
y  yn
x  x  xn 1
y  y  yn 1
 The FORWARD Difference Calc
dy
dx

x  xn
y fwd
x fwd
Engineering/Math/Physics 25: Computational Methods
16
yn 1  yn

xn 1  xn
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
dy/dx by Discrete-Point Difference
 The BACKWARD Difference Calc
dy
dx
x  xn
ybkwd yn  yn 1


xbkwd xn  xn 1
 The CENTRAL Difference Calc
dy
dx
x  xn
ycent yn 1  yn 1


xcent xn 1  xn 1
Engineering/Math/Physics 25: Computational Methods
17
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Finite Difference Example
Forward
Difference
800
Analytical
700
600
y
500
400
300
200
100
0
0
2
4
6
8
10
12
14
16
18
x
Engineering/Math/Physics 25: Computational Methods
18
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Discrete Point dy/dx
x
y
Fwd dy/dx
1.216
0.382
0.9248
2.263
1.350
0.2445
3.032
1.538
0.5390
4.062
2.093
-1.0275
5.122
1.003
0.1208
6.124
1.124
6.8226
7.100
7.781
6.6722
8.071 14.260
-0.2581
9.215 13.964
-11.5670
10.046
4.353
41.9968
11.168 51.459
-26.9751
12.228 22.859
97.8991
13.025 100.873
5.0713
14.135 106.504
-67.7185
15.204 34.153 123.3603
16.015 134.249
Bk dy/dx Cent dy/dx
0.9248
0.2445
0.5390
-1.0275
0.1208
6.8226
6.6722
-0.2581
-11.5670
41.9968
-26.9751
97.8991
5.0713
-67.7185
123.3603
Engineering/Math/Physics 25: Computational Methods
19
0.6368
0.4131
-0.2559
-0.4699
3.4281
6.7476
2.9225
-5.0145
19.2027
8.4818
26.6084
43.8556
-30.6223
14.7592
140
120
100
80
y
Pt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
60
40
20
0
0
2
4
6
8
x
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
10
12
14
16
Compare Fwd, Bkwd, Cent Diffs
Finite Difference Calc
6
140
F/avg
B/avg
C/avg
5
120
4
100
[dy/dy]/average
3
2
y
1
80
60
0
2
-1
3
4
5
6
7
8
9
10
11
12
13
14
40
-2
20
-3
-4
0
0
2
4
Engineering/Math/Physics 25: Computational Methods
20
6
8
Point
x
10
12
14
16
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
15
Finite Difference Fence-Post Errors
 If we have data vectors for x & f(x) we
can calc m = df(x)/dx by the Fwd, Bkwd
or Central Difference methods
 If there are 1 to n Data points then can
NOT calc
• mfwd for pt-n (cannot extend fwd beyond n-1)
• mbk for pt-1 (cannot extend bkwd beyond 1)
• mcnt for pt-1 and pt-n (cannot extend bk
beyond 1, cannot extend fwd beyond n)
Engineering/Math/Physics 25: Computational Methods
21
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Cap Voltage – Integrate & Plot
 25
i  10mA  300mA * e t 5 / S * sin 
 s

t

+ v(t) 1.0 mF
i(t)
1  t



vt  
i
x
dx

Q
o


0

1µF 
in this case : Qo  0 Coulombs
Engineering/Math/Physics 25: Computational Methods
22
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Cap Charging
 The Current can Be integrated Analytically
to find v(t), but it’s Painful
V
 25
5 t 
vt   10 t  0.484V * e 5 sin 
S
 S


 25
t   25 cos

 S

t   3.804V

 Let’s Tackle The Problem Numerically
 Use the PieceWise Property
y 7    f t dt   f t dt   f t dt     f t dt   f t dt
7
1
0
0
2
1
OR y t   y01  y12    yn 1n  ynt
Engineering/Math/Physics 25: Computational Methods
23
6
7
5
6
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Digression
 For More Info on
yt   y01  y12    yn1n  ynt
 See pages 333-335 from
Engineering/Math/Physics 25: Computational Methods
24
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
PieceWise Integration
H t   H t  1  yt   H t  1  vt t
in this case : t  0.33 mS
Engineering/Math/Physics 25: Computational Methods
25
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
PieceWise Integration Illustrated
1
GREEN Area   RED Area 
1µF
v40mS  
1
This Area 
1µF
Engineering/Math/Physics 25: Computational Methods
26
1  t



vt  
i
x
dx

1µF  0
v80mS  
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Cap Chrg PieceWise Integration
 Game Plan
t i x 
t i x 
1  t

vt  
ix dx  Qo  
dx  0  
dx



0
0
0

1µF 
1µF
C
• Make Function for i(t)/C
• Divide 300 mS interval into 1 mS pieces
• Use 1-300 FOR Loop to collect
– Vector for Time-Plot
– Use ΔV summation to Create a
V-Plotting Vector
 File List
• Fcn → iOverC_CapCharge.m
• Calc & Plot → Cap_Charge_Soln_1111.m
Engineering/Math/Physics 25: Computational Methods
27
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
% B. Mayer 08Nov11
% Cap Charging: Piecewise Ingegration
% Cap_Charge_Soln_1111.m
%
% use 500 pts using LinSpace
% => Ask user for max time
tmax = input('Enter Max Time in Sec = ')
tmin = 0; n = 500;
t = linspace(tmin,tmax,n); % in Sec
TimePts =length(t) % 2X check number of time points
%
% Initalize the Vminus1 & Plotting Vectors
Vminus1 = 0;
Vplot = 0;
tplot = 0;
%
% Use FOR Loop with Lobratto Integrating quadl function on Cap Charge
% Function
for k = 1:n-1
tplot(k) = t(k);
del_v(k) = quadl('iOverC_CapCharge', t(k), t(k+1));
% The Incremental Area Under the Curve; can be + or Vplot(k) = Vminus1 + del_v(k);
Vminus1 = Vplot(k);
end
plot(1000*tplot, del_v), xlabel('time (mS)'), ylabel('DelV (V)'),...
title('Capacitor Voltage PieceWise Integral'), grid
disp('Showing del_v PLOT - hit any key to show V(t) plot')
pause
plot(1000*tplot, Vplot), xlabel('time (mS)'), ylabel('Cap Potential (V)'),...
title('Capacitor Voltage'), grid
Engineering/Math/Physics 25: Computational Methods
28
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
File Codes
function [Cap_Charge] = iOverC_CapCharge(time)
Cap_Charge = (1/0.001)*(10 + 300*exp(-5*time).*sin(25*pi*time))/1000;
% Cap Charge for Prob for Chp9 in COULOMBS
Units Analysis
 Examine the
Integrand from
i t 
i  dt
v
dt  
C
C
 The Integrand Units
i  dt
µA  mS

C
µF
 Recall From
ENGR10 A, S, & F
in SI Base Units
Engineering/Math/Physics 25: Computational Methods
29
• A → A (a base unit)
• S → S (a base unit)
• F → m−2•kg−1•S4•A2
• V → m2•kg•S−3•A−1
2
A  mS 1
A

S
m
kg
3

 10
1 F
1 S 4 A2
i  dt
 m 2  kg  S 3  A1
 Or
C
 But m2  kg  S 3  A1  Volts
i  dt

V
C

Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Result
Capacitor Voltage
8
v40mS 
7
Cap Potential (V)
6
5
4
3
v80mS 2
1
0
0
50
100
Engineering/Math/Physics 25: Computational Methods
30
150
200
time (mS)
250
300
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
All Done for Today
Trapezoidal
Rule
Use Trapezoids to
approximate the area
under the curve:
y
n trapezoids
…
a
b
ba
Width, Δx =
n
Engineering/Math/Physics 25: Computational Methods
31
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
x
Engr/Math/Physics 25
Appendix
f x   2 x  7 x  9 x  6
3
2
Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
BMayer@ChabotCollege.edu
Engineering/Math/Physics 25: Computational Methods
32
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
dy/dx example
x = [1.215994, 2.263081, 3.031708,
4.061534, 5.122477, 6.12396, 7.099754,
8.070701, 9.215382, 10.04629, 11.16794,
12.22816, 13.02504, 14.13544, 15.20385,
16.01526]
y = [0.381713355
1.350058777
1.537968679 2.093069052 1.002924647
1.123878013 7.781303297 14.2596343
13.96413795 4.352973409 51.45863097
22.85918559 100.8729773 106.5041434
34.15277499 134.2488143]
plot(x,y),xlabel('x'), ylabel('y'), grid
Engineering/Math/Physics 25: Computational Methods
33
Bruce Mayer, PE
BMayer@ChabotCollege.edu • ENGR-25_Lec-21_Integ_Diff.ppt
Download