Professional Documents
Culture Documents
Objectives:
- Recall indefinite & definite integration.
- Use MATLAB to evaluate double integrals.
Integration:
Syntax (1):
int (f) : Compute definite and indefinite integrals analytically, F, so that diff(F) = f.
That is, int (f) returns the indefinite integral or antiderivative of function similar to differentiation.
Note: We must use syms command for constructing symbolic variables before using int.
Example (1):
Evaluate: x sec xdx, cos
2
x dx, tan 3 xdx, x sin 4 xdx.
0
Solution:
Page 1 of 4
Pharos University in Alexandria
Faculty of Engineering Fall 2022-2023
Department of Basic Sciences
Example (2):
b
Write an M-file that evaluates
a
f ( x)dx using if statement to ensure that a is less than b and displays
the result or an error message if condition is not matched.
Solution:
Syntax (2):
integral(fun,xmin,xmax) for numerical integration where fun Integrand, specified as a function handle,
which defines the function to be integrated from xmin to xmax.
Page 2 of 4
Pharos University in Alexandria
Faculty of Engineering Fall 2022-2023
Department of Basic Sciences
Example (3):
Calculate the integral e ax dx
Note: without assigning a value to a, MATLAB assumes that a represents a complex number, and
therefore returns a piecewise answer that depends on the argument of a. If you are only interested in the
case when a is a positive real number, use assume to set an assumption on a.
Hint: assume( condition): Sets assumption on symbolic object and states that condition is valid for all
symbolic variables in condition. It also removes any assumptions previously made on these symbolic
variables.
Solution:
M-File Run In Command Window
syms a x
assume(a > 0)
f = exp(-a*x^2);
int(f, x, -inf, inf) ans = pi^(1/2)/a^(1/2)
Double Integration
Xmin: Lower limit of x, specified as a real scalar(number) value that is either finite or infinite.
Xmax: Upper limit of x, specified as a real scalar value that is either finite or infinite.
Ymin: Lower limit of y, specified as a real scalar value that is either finite or infinite. You can specify
ymin to be a function handle (a function of x) when integrating over a nonrectangular region.
Ymax: Upper limit of y, specified as a real scalar value that is either finite or infinite. You also can
specify ymax to be a function handle (a function of x) when integrating over a nonrectangular region.
Page 3 of 4
Pharos University in Alexandria
Faculty of Engineering Fall 2022-2023
Department of Basic Sciences
Example (4):
/2 1
cos x d y d x
b. 0 cos x
5 x
x (1+ y ) d y d x
c. 0 0
2 2
2
ex d y d x
d. 0 y
Solution:
Page 4 of 4