Page 1
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt1
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Bruce Mayer, PELicensed Electrical & Mechanical Engineer
[email protected]
Engr/Math/Physics 25
Chp9: Integration
& Differentiation
Page 2
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt2
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
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
Page 3
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt3
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
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: dtmvdF • Heat Flux: dxdTkq
• Drag on a Parachute: mcvmgdtdv • Capacitor Current: dtdVCi
Page 4
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt4
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Why Differentiate, Integrate? Integration: Integration is commonplace in
Science and Engineering
Calculation of Geographic Areas
River ChannelCross Section
Wind-ForceLoading
Page 5
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt5
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
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
b
adxxfA
Page 6
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt6
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Review: Differentiation Differentiation: rate of change of a
dependent variable with respect to anindependent variable.
x
xfxxfLimxyLim
dxdy ii
xxxx i
00
Page 7
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt7
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Integral Properties Indefinite Intregral
w/ Variable End-Pts Constxfdxxgxy
Initial/Final Value Formulations
00
ytfdxxgtyt
tfydxxgty
ytfdxxgty
t
t
Piecewise Property
a
x
y
c
b
c
a
b
c
b
adxxfdxxfdxxf
Linearity → for Constants p & q
b
a
b
a
b
a
dxxgqdxxfp
dxxgqxfp
Page 8
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt8
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Derivative Properties PRODUCT Rule• Given
xgxfxy • Then • Then
QUOTIENT Rule• Given
dxdfxg
dxdgxf
dxdy
xg
xfxy
xg
dxdgxf
dxdfxg
dxdy
2
Page 9
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt9
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Alternative Quotient Rule Restate Quotient as rational Exponent,
then apply Product rule; to whit: Then
Putting 2nd term over common denom
1 xgxfxgxfxy
dxdfxg
dxdgxgxf
dxdy 121
22 xg
dxdfxg
xgdxdgxf
dxdy
Page 10
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt10
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Why Numerical Methods? Numerical
Integration • 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
Page 11
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt11
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
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
Page 12
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt12
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Strip-Top Effect
Parabolic (Simpson’s) Form
Trapezoidal Form
• Higher-Order-Polynomial Tops Lead to increased, but diminishing, accuracy.
Page 13
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt13
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Strip-Count Effect
Adaptive Integration → INCREASE the strip-Count in Regions with Large SLOPES• More Strips of Constant
Width Tends to work just as well
10 Strips 20 Strips
Page 14
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt14
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
dy/dx by Finite Difference Approx.
Nx
N
x
xi-1 xi xi+1
A
BC
x-x x x+x
x x
y(x)
y(x)
y(x-Δx)
y(x)
y(x+Δx)
Derivative at Point-x :xy
dxdym
• Forward Difference
x
xyxxyxxx
xyxxyxym fwd
• Backward Difference
x
xxyxyxxx
xxyxyxymbkwd
mfwd
mbkwd
Page 15
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt15
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
dy/dx by Finite Difference Approx.
Nx
N
x
xi-1 xi xi+1
A
BC
x-x x x+x
x x
y(x)
y(x)
y(x-Δx)
y(x)
y(x+Δx)
Central Difference = Average of fwd and bkwd Slopes :
x
xxyxxyx
xxyxyx
xyxxy
mmm bkwdfwdcent
2
21
2
mcent
Page 16
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt16
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
dy/dx by Discrete-Point Difference From Previous LET
11
11
nnn
nnn
yyyyyyyyxxxxxxxx
The FORWARD Difference Calc
nn
nn
fwd
fwd
xx xxyy
xy
dxdy
n
1
1
Page 17
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt17
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
dy/dx by Discrete-Point Difference The BACKWARD Difference Calc
The CENTRAL Difference Calc
11
11
nn
nn
cent
cent
xx xxyy
xy
dxdy
n
1
1
nn
nn
bkwd
bkwd
xx xxyy
xy
dxdy
n
Page 18
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt18
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Finite Difference ExampleForwardDifference Analytical
0 2 4 6 8 10 12 14 16 180
100
200
300
400
500
600
700
800
x
y
Page 19
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt19
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Discrete Point dy/dxPt x y Fwd dy/dx Bk dy/dx Cent dy/dx
1 1.216 0.382 0.92482 2.263 1.350 0.2445 0.9248 0.63683 3.032 1.538 0.5390 0.2445 0.41314 4.062 2.093 -1.0275 0.5390 -0.25595 5.122 1.003 0.1208 -1.0275 -0.46996 6.124 1.124 6.8226 0.1208 3.42817 7.100 7.781 6.6722 6.8226 6.74768 8.071 14.260 -0.2581 6.6722 2.92259 9.215 13.964 -11.5670 -0.2581 -5.0145
10 10.046 4.353 41.9968 -11.5670 19.202711 11.168 51.459 -26.9751 41.9968 8.481812 12.228 22.859 97.8991 -26.9751 26.608413 13.025 100.873 5.0713 97.8991 43.855614 14.135 106.504 -67.7185 5.0713 -30.622315 15.204 34.153 123.3603 -67.7185 14.759216 16.015 134.249 123.3603
0 2 4 6 8 10 12 14 160
20
40
60
80
100
120
140
x
y
Page 20
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt20
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Compare Fwd, Bkwd, Cent Diffs
0 2 4 6 8 10 12 14 160
20
40
60
80
100
120
140
x
y
Finite Difference Calc
-4
-3
-2
-1
0
1
2
3
4
5
6
2 3 4 5 6 7 8 9 10 11 12 13 14 15
Point
[dy/
dy]/a
vera
ge
F/avg B/avg C/avg
Page 21
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt21
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
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)
Page 22
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt22
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Cap Voltage – Integrate & Plot
i(t)
+ v(t) -
1.0 mF
t
semAmAi St 25sin**30010 /5
Coulombs 0 :case in this1
10
o
o
t
Q
QdxxiµF
tv
Page 23
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt23
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Cap Charging The Current can Be integrated Analytically
to find v(t), but it’s Painful
VtS
tS
eVtSVtv t 804.325cos2525sin5*484.010 5
Let’s Tackle The Problem Numerically Use the PieceWise Property
ntnn yyyyty
dttfdttfdttfdttfdttfy
11201
7
0
1
0
2
1
6
5
7
6
OR
7
Page 24
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt24
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Digression For More Info on ntnn yyyyty 11201
See pages 333-335 from
Page 25
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt25
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
PieceWise Integration
mS 33.0:case in this
11
t
ttvtHtytHtH
Page 26
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt26
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
PieceWise Integration Illustrated
Area This1
140
µF
mSv
Area REDArea GREEN1
180 µF
mSv
t
dxx
iµF
tv
01
1
Page 27
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt27
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Cap Chrg PieceWise Integration Game Plan• 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
tt
o
tdx
Cxidx
µFxiQdxxi
µFtv
0000
111
Page 28
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt28
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
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
% 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 VectorsVminus1 = 0;Vplot = 0;tplot = 0;%% Use FOR Loop with Lobratto Integrating quadl function on Cap Charge% Functionfor 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);endplot(1000*tplot, del_v), xlabel('time (mS)'), ylabel('DelV (V)'),... title('Capacitor Voltage PieceWise Integral'), griddisp('Showing del_v PLOT - hit any key to show V(t) plot')pauseplot(1000*tplot, Vplot), xlabel('time (mS)'), ylabel('Cap Potential (V)'),... title('Capacitor Voltage'), grid
Page 29
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt29
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Units Analysis Examine the
Integrand from
The Integrand Units
Or
• A → A (a base unit)• S → S (a base unit)• F → m−2•kg−1•S4•A2
• V → m2•kg•S−3•A−1
µFmSµA
Cdti
Cdtidt
Ctiv
Recall From ENGR10 A, S, & F in SI Base Units
24
23
1101
1 ASkgmSA
FmSA
132 ASkgmCdti
But VoltsASkgm 132
VCdti
Page 30
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt30
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Result
0 50 100 150 200 250 3000
1
2
3
4
5
6
7
8
time (mS)
Cap
Pot
entia
l (V)
Capacitor Voltage
mSv 40
mSv 80
Page 31
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt31
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
All Done for Today
TrapezoidalRule
Use Trapezoids to approximate the area under the curve:
a b
…
b anWidth, Δx =
n trapezoids
x
y
Page 32
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt32
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Bruce Mayer, PELicensed Electrical & Mechanical Engineer
[email protected]
Engr/Math/Physics 25
Appendix 6972 23 xxxxf
Page 33
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt33
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
dy/dx examplex = [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