©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE...

33
©1999 BG Mobasseri 1 06/20 June 21, ‘99 fx () dx a b

Transcript of ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE...

Page 1: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 1 04/19/23

June 21, ‘99

f x( )dxa

b

Page 2: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 2 04/19/23

EVALUATING DEFINITE INTEGRALS

MATLAB can evaluate definite integrals like

This is provided that the integrand f(x) be

available as a function, not an array of numbers

f (x)dxa

b

Page 3: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 3 04/19/23

HOW DOES MATLAB DO IT?

The primary function for evaluating definite

integrals is quad8

quad8 has the following syntax– q=quad8(‘function’,a,b)

This is equivalent to the expression

( function)dxa

b

Page 4: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 4 04/19/23

BUILT-IN MATLAB FUNCTIONS

Evaluate the following

Since cosine is a built-in MATLAB function;

y=quad8(‘cos’,0,3*pi/2)

cos(x)0

3π 2

∫ dx

Page 5: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 5 04/19/23

USER-DEFINED FUNCTION(we haven’t covered function writing)

You can integrate functions that are not part of

MATLAB library.

For example, you can write a function of your

own such as gauss,

y =1

2 πe

−x2

2

-3 -2 -1 0 1 2 30

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

Page 6: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 6 04/19/23

Try it! area under humps

humps is a pre-defined function in MATLAB. Let’s

first plot it usingx=0:0.01:2;

plot(x,humps(x))

Now let’s find the area over a number of intervals– area=quad8(‘humps’,0,0.5)

– area=quad8(‘humps’,0,1)

– area=quad8(‘humps’,0,2)

Page 7: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 7 04/19/23

APPROXIMATION TO INTEGRALS - trapz

Function trapz uses areas of trapezoids to

approximate the area under the curve

-3 -2 -1 0 1 2 30

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

x=0:0.01:2;y=humps(x)area=trapz(x,y)

You might be surprisedhow large the answeris?answer next

Page 8: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 8 04/19/23

Sample Spacing

trapz assumes unit spacing between samples

If that is not true, the output of trapz must be

scaled by the actual spacing, e.g. 0.1

So what is the right answer in the previous slide?

1

Page 9: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 9 04/19/23

In all future slides...

Use trapz in all future integration cases

Page 10: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 10 04/19/23

Try it !

Energy of a signal

Using trapz, find the energy of a gaussian pulse

(slide 5) in the range (-1,1)

E = s2 t( )T1

T2

∫ dt

Page 11: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 11 04/19/23

EXTENSION OF 1D INTEGRALS

1-D integral can geometrically be interpreted as

an area.

It is possible to evaluate volumes, not by

multidimensional integrals as is generally done ,

but as 1-D integrals.

Page 12: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 12 04/19/23

DEFINING VOLUMES

There are a number of ways a 3D shape can be

generated– Sweeping a Cross Section

– The Disc Method

– The Washer Method

– The Shell Method

Page 13: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 13 04/19/23

CROSS-SECTIONAL METHOD

Imagine sweeping a 1D shape, of varying cross

sections A(x), along a path. This action will

generate a swept volume.

x

V = A x( )a

b

∫ dx

= (a×b)0

c

∫ dx=abcb

a

c

Page 14: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 14 04/19/23

VOLUME OF A PYRAMID

In problems like this you must first do two things– write a function for the cross section as a function

of x

– determine the lower and upper limit of the sweep

x

h

b

A x( ) =bh

h−x( ) ⎡ ⎣ ⎢

⎤ ⎦ ⎥2

Page 15: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 15 04/19/23

THE DISC METHOD

Take a 1D curve f(x) and revolve it around the x-

axis. This is a volume of revolution:– semi-circle---> sphere

– triangle --> cone

Every cross section is a circle. The radius of the

circle at xo is f(xo).

V = π f x( )[ ]2a

b

∫ dx

Page 16: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 16 04/19/23

Try it! REVOLVING A SINUSOID

Take one period of and revolve it

around the x-axis. Plot the shape then find the

volume of the revolution

1+cos2πx( )

-1-0.5

00.5

1

-1-0.5

00.5

10

0.2

0.4

0.6

0.8

1

Page 17: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 17 04/19/23

THE SHELL METHOD

Define a function f(x) in a<x<b. Revolve R

around the y-axis

Examples:– revolve a rectangle --> cylinder with a thickness

– revolve a circle --> torus/donut

yf(x)

x

RV= 2πxfx( )dxa

b∫

Page 18: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 18 04/19/23

Try it!

Let f(x)=1-(x-2)2 for 1<x<3. Revolve this around

the y-axis and find its volume

31

Page 19: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 19 04/19/23

ARC LENGTH

Another important application of integrals is

finding arc lengths

xa b

f(x)

L= 1+ f' x( )[ ]2a

b∫ dx

Page 20: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 20 04/19/23

PARAMETRIC CURVES

It is frequently easier to work with a parametric

representation of a curve,i.e.

x=f(t)

y=g(t)

For example, a circle

x(t)=rcos(t)

y(t)=rsin(t)

r

t

Page 21: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 21 04/19/23

LENGTH OF PARAMTERIC CURVES

Using derivatives of f(t) and g(t)

L = f' t( )[ ]2 + g' t( )[ ]2a

b

∫ dt

Page 22: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 22 04/19/23

CYCLOID

P

P

P

xfull perimeter=2.pi.r

Path length traversed by a point on a wheel is of

interest

Page 23: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 23 04/19/23

LENGTH OF A CYCLOID

The parametric equation of a cycloid with r=1 is

given by

x=t-sin(2.pi.t)

y=1-cos(2.pi.t)

First, plot the cycloid for 0< t <1.

Then find its length for one cycle and compare it

with the horizontal distance

Page 24: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 24 04/19/23

INTEGRALS IN POLAR COORDINATES

A curve can be represented in polar coordinates

by

Equivalently

r = f θ( )

x = f θ( )cosθ( )y= f θ( )sinθ( ) ⎧ ⎨ ⎩

r = f θ( )

θ

θ

x

y

Page 25: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 25 04/19/23

CURVE LENGTH

The length of a curve represented in polar

coordinates is given by

L = ′ f θ( )[ ]2 + f θ( )[ ]2α

β

∫ dθ

Page 26: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 26 04/19/23

PERIMETER OF AN ELLIPSE

Find the perimeter of an ellipse given by

r = 63+2cosθ

′ f θ( ) =−12sinθ

(3+ 2cosθ)2

Page 27: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 27 04/19/23

cardioid, 3-leaved rose

cardioid is defined by r=1+cosθ. 3-leaved rose is given by r=cos3θ.

0.5

1

1.5

2

30

210

60

240

90

270

120

300

150

330

180 0

0.2 0.4 0.6 0.8 1

30

210

60

240

90

270

120

300

150

330

180 0

Page 28: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 28 04/19/23

LENGTH OF A cardioid

We need the derivative of f(θ– f’(θ -sin(θ

Then,

L = sin2θ + (1+ (cosθ))2

−π2

π2

∫ dθ = 2+ 2cosθ−π2

π2

∫ dθ

Page 29: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 29 04/19/23

AREA IN POLAR COORDINATES

A=12

f θ( )[ ]2dθα

β

∫f (θ)

Page 30: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 30 04/19/23

AREA OF AN ELLIPSE

For the ellipse given by

find its area and verify

r = 63+2cosθ

Page 31: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 31 04/19/23

AREA OF A cardioid

Here we have

Then

f θ( ) =1+ cosθ

A=120

∫ f θ( )[ ]2dθ =120

∫ 1+cosθ[ ]2dθ

Page 32: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 32 04/19/23

HOMEWORK-1

Find the length and area of a cardioid. Use the relevant equations for length and area given previously

0.5

1

1.5

2

30

210

60

240

90

270

120

300

150

330

180 0

Page 33: ©1999 BG Mobasseri18/25/2015 June 21, ‘99. ©1999 BG Mobasseri28/25/2015 EVALUATING DEFINITE INTEGRALS  MATLAB can evaluate definite integrals like

©1999 BG Mobasseri 33 04/19/23

HOMEWORK-2

Find the energy of the bond clip using trapz. This

routine assumes unit sample spacing. However,

bond is sampled at 8KHz. Take this into account.