[email protected] engr-25_lec-21_integ_diff.ppt 1 bruce mayer, pe engineering/math/physics...

33
[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected] Engr/Math/Physics 25 Chp9: Integration & Differentiation

Upload: stewart-norris

Post on 26-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

[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

[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

[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

[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

[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

[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

xfxxfLim

x

yLim

dx

dy ii

xxxx i

00

[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

[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

dx

dfxg

dx

dgxf

dx

dy

xg

xfxy

xg

dxdg

xfdxdf

xg

dx

dy2

[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 xgxfxg

xfxy

dx

dfxg

dx

dgxgxf

dx

dy 121

22 xg

dxdf

xg

xgdxdg

xf

dx

dy

[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

[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

[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.

[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

[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

B

C

x-x x x+x

x x

y(x)

y(x)

y(x-Δx)

y(x)

y(x+Δx)

Derivative at Point-x :x

y

dx

dym

• Forward Difference

x

xyxxy

xxx

xyxxy

x

ym fwd

• Backward Difference

x

xxyxy

xxx

xxyxy

x

ymbkwd

mfwd

mbkw

d

[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

B

C

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

xxyxxy

x

xxyxy

x

xyxxy

mmm bkwdfwdcent

2

2

1

2

mcent

[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

yyyyyyyy

xxxxxxxx

The FORWARD Difference Calc

nn

nn

fwd

fwd

xx xx

yy

x

y

dx

dy

n

1

1

[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 xx

yy

x

y

dx

dy

n

1

1

nn

nn

bkwd

bkwd

xx xx

yy

x

y

dx

dy

n

[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

[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

[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]

/ave

rag

e

F/avg B/avg C/avg

[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)

[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 25

sin**30010 /5

Coulombs 0 :case in this

1

10

o

o

t

Q

QdxxiµF

tv

[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

eVtS

Vtv t 804.3

25cos25

25sin5*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

[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

[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

[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt26

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

PieceWise Integration Illustrated

Area This1

1

40

µF

mSv

Area REDArea GREEN1

180

µFmSv

t

dxx

Ft

v0

1

1

[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

C

xidx

µF

xiQdxxi

µFtv

0000

11

1

[email protected] • ENGR-25_Lec-21_Integ_Diff.ppt28

Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods

File C

od

es

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

[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

µF

mSµA

C

dti

C

dtidt

C

tiv

Recall From ENGR10 A, S, & F in SI Base Units

24

23

110

1

1 AS

kgmSA

F

mSA

132

ASkgmC

dti

But VoltsASkgm 132

VC

dti

[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

[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 a

n

Width, Δx =

n trapezoids

x

y

[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

[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