Integration - University of Michigan
Download
Report
Transcript Integration - University of Michigan
Math Review with Matlab:
Calculus
Integration
S. Awad, Ph.D.
M. Corless, M.S.E.E.
D. Cinpinski
E.C.E. Department
University of Michigan-Dearborn
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Integration
Definite and Indefinite Integrals
Integral Pairs
Closed Form Integrals
Int Command
Closed Form Example
Multiple Independent Variable Example
Numerical Integration
Quad Command
Numerical Integration Example
Closed Form and Numerical Integration Example
2
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Definite & Indefinite Integrals
A definite integral represents the area under a curve
f(x) between the lower limit a and the upper limit b
I DEFINITE f ( x)dx
b
a
An integral is considered to be indefinite if the upper
and lower limits are not specified
I INDEFINITE f ( x)dx
3
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Integral Pairs
Some indefinite integrals can be thought of as the
inverse of differentiation
A few common integral pairs are shown below
adx ax c
n1
ax
n
ax
dx n 1 c
ax
e
ax
e
dx a c
a
x dx a ln(x) c
a sin(bx)
a
cos(
bx
)
dx
c
b
a cos(bx)
a
sin(
bx
)
dx
c
b
Note that due to initial conditions, arbitrary integral pairs are
not unique and may differ by a constant of integration, c
4
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Closed Form Integrals
Closed form integrals are integrals which can be
expressed as explicit functions
The integral pairs on the previous slide are examples of
closed form integrals
Techniques such as partial fraction expansion,
integration by parts, and integration by substitution
can be used to express some integrals in closed form
It is not always possible to find the closed form for the
integral of an arbitrary function
5
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Evaluation of Definite Integral
If a closed form indefinite integral exists, it can be used to
evaluate a definite integral over a region of integration
An integral from an arbitrary lower limit
to a fixed upper limit is denoted as:
F ( x) f (u)du
x
Thus definite integral from a lower limit a to an upper limit b
can be evaluated using:
b
a
b
a
f ( x)dx f ( x)dx f ( x)dx
a
b
x0
x0
f ( x)dx F (b) F (a) F ( x) a
b
6
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Int Command
The int command is used to solve integrals which can
be expressed in closed form
int(s) returns the indefinite integral of the symbolic
variable s with respect to its default symbolic variable
int(s,v) returns the indefinite integral of the symbolic
variable s with respect to the symbolic variable v
int(s,a,b) returns the definite integral of the symbolic
variable s with respect its default symbolic variable from a to b
int(s,v,a,b) returns the definite integral of the symbolic
variable s with respect to the symbolic variable v from a to b
7
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Closed Form Example
Given the function, f(x):
1) Use the int command to determine the
Closed Form Indefinite Integral, F(x):
f ( x) sin(2x)
F ( x) f ( x)dx
2) From the closed form integral, F(x), determine
the definite integral of f(x) from 0 to p/2
3) Use the int command to directly determine
the definite integral of f(x) from 0 to p/2
4) Determine and plot a function A(z)
representing the general area under f
from 0 to any arbitrary point z
A 2
/2
f ( x)dx
0
z
A( z) f ( x)dx
0
8
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Indefinite Closed Form
Matlab can be used to verify the integral pair shown on a
previous slide
The integration variable parameter does not need to be
specified since x is the only variable in the expression, hence
it will be the default variable of integration
» syms x
» f=(sin(2*x));
f ( x) sin(2x)
» F=int(f)
F =
-1/2*cos(2*x)
cos(2x)
F ( x) f ( x)
2
9
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Definite Integral Evaluation
The definite integral can be
evaluated from the indefinite integral
using the relationship:
» Fb=subs(F,'x',pi/2)
Fb =
0.5000
» Fa=subs(F,'x',0)
Fa =
-0.5000
cos(2x)
F ( x)
2
F ( / 2) 0.5
F (0) 0.5
» A_pidiv2 = Fb - Fa
A_pidiv2 =
1
b
a
f ( x)dx F (b) F (a)
/2
A 2 sin(2x)dx 1
0
10
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Matlab Direct Evaluation
Since f(x) has a closed form, the int command can be
used to directly determine the definite integral
» f=(sin(2*x));
» F_definite=int(f,0,pi/2)
F_definite =
1
/2
A / 2 sin(2x)dx 1
0
11
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Area Under Curve
A general function, A(z), used to plot the area under the
curve f(x) to an arbitrary point z can be determined as follows:
»
»
»
»
syms z
F_z = subs(F,x,z);
F_0 = subs(F,x,0);
A_z = F_z - F_0
A_z =
-1/2*cos(2*z)+1/2
z
A( z) f ( x)dx
0
A( z) F ( x) x z F ( x) x0
cos(2 z) 1
A( z)
2
2
» A_z_pidiv2=subs(A_z,z,pi/2)
A_z_pidiv2 =
1
A( 2) 1
12
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Graphical Definite Integral
»
»
»
»
»
»
Area under f(x)
from 0 to /2 = 1
Definite Integral
Evaluation A(/2)
subplot(2,1,1)
ezplot(f,0,pi)
grid on
subplot(2,1,2)
ezplot(A_z,0,pi)
grid on
Area 1
A 2 1
13
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Multiple Independent
Variable Example
Given the function f(t,x,y):
f (t, x, y) t 2tx 3txy
Use Matlab to determine the closed form integrals with
respect to the different independent variables:
1) Integrate f with respect to t :
F (t ) f (t, x, y)dt
2) Integrate f with respect to x :
F ( x) f (t, x, y)dx
3) Integrate f with respect to y :
F ( y) f (t, x, y)dy
14
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Default Integration
Integrating with respect to the default independent
variable will integrate with respect to x
» syms t x y
» f=sym('t + 2*t*x + 3*x*y*t');
» Fx = int(f)
f (t, x, y) t 2tx 3txy
Fx =
t*x+t*x^2+3/2*x^2*y*t
3 2
F ( x) tx tx tyx
2
2
15
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Other Independent Variables
Integration of f(t,x,y) with respect to t or y must be
explicitly specified as an input argument to int
» Ft=int(f,t)
f (t, x, y) t 2tx 3txy
Ft =
1/2*t^2+t^2*x+3/2*x*y*t^2
1 2
3 2
2
F (t ) t xt xyt
2
2
» Fy=int(f,y)
Fy =
t*y+2*x*y*t+3/2*x*y^2*t
3 2
F ( y) ty 2txy txy
2
16
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Numerical Integration
Some functions do not have closed form integrals
A definite integral can be numerically approximated
provided that the function is defined over the region of
interest
Numerical integration is performed by subdividing the
integration region into very small regions, approximating
the area in each region, and summing the areas
If as the length of the subintervals tends to 0 and the
summation of areas tends to a unique limit, I, the
definite integral over the interval is I
17
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Quad Command
The quad command is used to numerically evaluate an
integral
Q = quad('f',a,b) approximates the integral of f(x)
from a to b
'f' is a string containing the name of an m-function to be
integrated. Function f must return a vector of output values
when given an input vector.
Q = Inf is returned if an excessive recursion level is
reached, indicating a possibly singular integral.
Typically a new m-function will be created for f when
numerically evaluating an integral
18
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Numerical Integration Example
Given the function, f(x):
The definite integral, F:
f ( x) sin(x)e
F
x2
2
f (x)dx
0
1) Use the symbolic toolbox to verify that the f(x) does not
have a closed form indefinite integral
2) Plot f(x) to ensure that the function is continuously
defined over the integration region
3) Numerically integrate f(x) to determine F
19
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
No Closed Form
No closed form can be found using Matlab’s
symbolic toolbox
» f_sym = sin(x)*exp(-x^2);
» int(f_sym)
Warning: Explicit integral could not be found.
> In C:\MATLABR11\toolbox\symbolic\@sym\int.m at
line 58
ans =
int(sin(x)*exp(-x^2),x)
20
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Continuous Plot
A plot verified that
f(x) is continuous
over the integration
region
Numerical
integration is
possible
» ezplot(f_sym)
» grid on
Continuous
0
2
21
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Numerical Integration
Must numerically evaluate the integral using the quad
command which requires a function as an input
Create a new m-function describing the function:
f ( x) sin( x)e
x2
The function must return a vector so be sure to use .*
and .^ notations where appropriate
function f = f_sin_exp_sqr( x )
f=sin(x).*exp(-x.^2);
22
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Numerical Integration
Use the quad command to perform the numerical
integration and evaluate the definite integral
» F_num_int = quad('f_sin_exp_sqr',0,pi/2)
F_num_int =
0.4024
2
sin(x)e
x2
dx 0.4024
0
23
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Closed Form and Numerical
Integration Example
Given the function f(x):
The definite integral, F:
1
f ( x) e tan ( x)
x
4
F f ( x)dx
0
1) Plot f(x) to ensure that the function is continuously defined
over the integration region
2) Use the symbolic toolbox to evaluate the definite integral
3) Numerically integrate f(x) to determine the definite integral
24
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Continuous Plot
»
»
»
»
Use ezplot to plot the
function
Verified continuous
from x=0 to x=4
syms x
f_sym=exp(x)+atan(x);
ezplot(f_sym)
grid on
25
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Symbolic Evaluation
Use the symbolic toolbox int command to evaluate
definite integral from the closed form integral
» defint_sym=int(f_sym,0,4)
Symbolic Expression
F_sym =
exp(4)+4*atan(4)-1/2*log(17)-1
» defint_dbl=double(F_sym)
defint_dbl =
57.4848
e
4
x
1
tan ( x) dx 57.4848
0
26
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Numerical Evaluation
Create a new m-function to represent f(x):
function f = f_exp_atan( x )
f=exp(x)+atan(x);
Use quad command to numerically evaluate the definite
integral and verify the previous symbolic result
» defint_numint=quad('f_exp_atan',0,4)
defint_numint =
57.4850
57.4850 57.4848
Small difference to numerical approximation
27
Calculus: Integration
Math Review with Matlab
U of M-Dearborn ECE Department
Summary
Definite integrals are evaluated over a continuous
interval and result in a number
Closed form indefinite integral functions exist for some
functions independent of the integration limits
The definite integrals can be evaluated from the
closed form indefinite integral if it exists
If a closed form indefinite integral does not exist, the
definite integral of continuous functions can still be
numerically approximated
28