2. The Symbolic Math Toolbox is a collection of tools for performing algebraic, calculus
and integral transform operations directly in MATLAB. When you pass a command to
Matlab to perform a symbolic operation, it asks Maple (an embedded mathematics
package) to do it and return the result to the Matlab command window.
To learn more about Symbolic MATLAB:
• Open MATLAB.
• Then type: ‘helpwin’ and press enter
• From the help topics click on ‘toolboxsymbolic’
Note: Only symbolic differentiation and integration are considered in the following
handout.
1 - Differentiation
The derivative of a function f(x) is defined to be a function f’(x) that is equal to the rate
of change of f(x) with respect to x:
d [ f ( x)]
f '( x) =
dx
There are many physical processes in which we want to measure the rate of change of a
variable. For example, velocity is the rate of change of position, and acceleration is the
rate of change of velocity.
Suppose that we have a function f(x) defined as follows:
f(x) = cos(2x) + sin(x)
The derivative f’(x) can be obtained by differentiating the above expression in terms of
the variable x:
f’(x) = –2 sin(2x) + cos(x)
To obtain a similar result in MATLAB, type the following command:
>> diff('cos(2*x)+sin(x)')
or, in a more general syntax,
2
3. >> f = 'cos(2*x)+sin(x)'
>> diff(f, 'x')
ans = –2*sin(2*x)+cos(x)
To graphically represent the original function and the first derivative, type the
following:
>> f = 'cos(2*x)+sin(x)'
>> figure(1)
>> ezplot(f)
>> f2 = diff(f, 'x')
>> figure(2)
>> ezplot(f2)
f(x) = cos(2x) + sin(x) f’(x) = -2 sin(2x) + cos(x)
Exercises:
df ( x)
1) Find for the following expressions:
dx
a) f ( x) = 3cos( x) + 7 sin( x)
b) f ( x) = x 4 − 3x 2 + x − 3
x
c) f ( x) =
x +1
2
df ( x) df 2 ( x)
2) Find and given that f ( x) = x 2 sin 3 x .
dx dx 2
3
4. 2 - Integration
- Indefinite integrals
Integration is the reverse process of differentiation. In differentiation, we start with a
function and proceed to find its derivative. In integration, we start with the derivative
and have to work back to find the function from which it has been derived. Hence, if:
dy
= f ( x)
dx
then the most general solution of the above expression is:
y = ∫ f ( x)dx
The above expression denotes the indefinite integral of the function f(x), while the
function f(x) itself is called the integrand.
Suppose that we have a function f(x) as follows:
f(x) = x4
Then,
x5
∫ x dx = 5 + c
4
Note: Without knowing the past history of the function, we have no indication of the
size of the constant of integration, since all trace of it is lost in the differentiation
process. All we can do is to indicate the constant term by a symbol, e.g. c.
To obtain a similar result in MATLAB, type the following command:
>> int('x^4')
ans = 1/5*x^5
Note: The constant is omitted in the MATLAB solution. Although we cannot determine
the value of c without extra information about the function, it is important that it is
always included in the result.
4
5. Exercises:
1) Find the indefinite integral of the following expressions:
a) y = ∫ ( x1 2 + 3x1 4 ) dx
b) y = ∫ ( e7 x + 1) dx
c) (
y = ∫ cos 4 x + 2 x dx )
x3 + 5 x + 3
d) y = ∫ dx
x2
- Definite integrals
The definite integral of a function f(x) over the interval [a,b] is defined to be the area
under the curve f(x) between x = a and x = b, as shown in the figure below.
b
f(x) ∫
a
f ( x)dx
f(a) f(b)
a b x
Suppose we have a function f ( x) = 2 x 2 + 1 , which we want to integrate over the
interval [2,5]:
5
2 x3 250 16
y = ∫ ( 2 x + 1)dx =
5
2
+ x = + 5 − + 2 = 81
2
3 2 3 3
5
6. To obtain a similar result in MATLAB, type the following command:
>> int('2*x^2+1','x',2,5)
ans = 81
1) Find the definite integral of the following expressions:
(5x − 2 x 2 + 4 x − 3)dx
10
a) y=∫ 3
5
y = ∫ ( x 7 )dx
1
b)
0
2 1
c) y = ∫ dx
1
x
Final Note: Integration and differentiation have a special relationship in that they can be
considered to be the inverse of each other – the integral of a derivative returns the
original function, and the derivative of an integral returns the original function, to
within a constant value.
6