Title: Calculus
1Calculus
Math Review with Matlab
Integration
- S. Awad, Ph.D.
- M. Corless, M.S.E.E.
- D. Cinpinski
- E.C.E. Department
- University of Michigan-Dearborn
2Integration
- 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
3Definite Indefinite Integrals
- A definite integral represents the area under a
curve f(x) between the lower limit a and the
upper limit b
- An integral is considered to be indefinite if the
upper and lower limits are not specified
4Integral Pairs
- Some indefinite integrals can be thought of as
the inverse of differentiation
- A few common integral pairs are shown below
- Note that due to initial conditions, arbitrary
integral pairs are not unique and may differ by a
constant of integration, c
5Closed 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
6Evaluation 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
- Thus definite integral from a lower limit a to an
upper limit b can be evaluated using
7Int 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
8Closed Form Example
1) Use the int command to determine the Closed
Form Indefinite Integral, F(x)
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
9Indefinite 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(2x))
Fint(f) F -1/2cos(2x)
10Definite Integral Evaluation
- The definite integral can be evaluated from the
indefinite integral using the relationship
Fbsubs(F,'x',pi/2) Fb 0.5000
Fasubs(F,'x',0) Fa -0.5000
A_pidiv2 Fb - Fa A_pidiv2 1
11Matlab Direct Evaluation
- Since f(x) has a closed form, the int command can
be used to directly determine the definite
integral
f(sin(2x)) F_definiteint(f,0,pi/2)
F_definite 1
12Area 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/2cos(2z)1/2
A_z_pidiv2subs(A_z,z,pi/2) A_z_pidiv2 1
13Graphical Definite Integral
- Area under f(x)
- from 0 to p/2 1
- Definite Integral Evaluation A(p/2)
subplot(2,1,1) ezplot(f,0,pi) grid on
subplot(2,1,2) ezplot(A_z,0,pi) grid on
14Multiple Independent Variable Example
- Given the function f(t,x,y)
- Use Matlab to determine the closed form integrals
with respect to the different independent
variables
1) Integrate f with respect to t
2) Integrate f with respect to x
3) Integrate f with respect to y
15Default Integration
- Integrating with respect to the default
independent variable will integrate with respect
to x
syms t x y fsym('t 2tx 3xyt') Fx
int(f)
Fx txtx23/2x2yt
16Other Independent Variables
- Integration of f(t,x,y) with respect to t or y
must be explicitly specified as an input argument
to int
Ftint(f,t) Ft 1/2t2t2x3/2xyt2
Fyint(f,y) Fy ty2xyt3/2xy2t
17Numerical 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
18Quad 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
19Numerical Integration Example
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
20No Closed Form
- No closed form can be found using Matlabs
symbolic toolbox
f_sym sin(x)exp(-x2) int(f_sym) Warning
Explicit integral could not be found. gt In
C\MATLABR11\toolbox\symbolic\_at_sym\int.m at line
58 ans int(sin(x)exp(-x2),x)
21Continuous Plot
- A plot verified that f(x) is continuous over the
integration region
- Numerical integration is possible
ezplot(f_sym) grid on
22Numerical 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
- The function must return a vector so be sure to
use . and . notations where appropriate
function f f_sin_exp_sqr( x ) fsin(x).exp(-x.
2)
23Numerical 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
24Closed Form and Numerical Integration Example
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
25Continuous Plot
- Use ezplot to plot the function
- Verified continuous from x0 to x4
syms x f_symexp(x)atan(x)
ezplot(f_sym) grid on
26Symbolic Evaluation
- Use the symbolic toolbox int command to evaluate
definite integral from the closed form integral
defint_symint(f_sym,0,4) F_sym
exp(4)4atan(4)-1/2log(17)-1
defint_dbldouble(F_sym) defint_dbl
57.4848
27Numerical Evaluation
- Create a new m-function to represent f(x)
function f f_exp_atan( x ) fexp(x)atan(x)
- Use quad command to numerically evaluate the
definite integral and verify the previous
symbolic result
defint_numintquad('f_exp_atan',0,4) defint_num
int 57.4850
- Small difference to numerical approximation
28Summary
- 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