Symbolic Math Toolbox    

Calculus

The Symbolic Math Toolboxes provide functions to do the basic operations of calculus; differentiation, limits, integration, summation, and Taylor series expansion. The following sections outline these functions.

Differentiation

Let's create a symbolic expression:

Then

differentiates f with respect to its symbolic variable (in this case x), as determined by findsym:

To differentiate with respect to the variable a, type

which returns :

To calculate the second derivatives with respect to x and a, respectively, type

or

which returns

and

which returns

Define a, b, x, n, t, and theta in the MATLAB workspace, using the sym command. The table below illustrates the diff command.

f
diff(f)
x^n
x^n*n/x
sin(a*t+b)
cos(a*t+b)*a
exp(i*theta)
i*exp(i*theta)

To differentiate the Bessel function of the first kind, besselj(nu,z), with respect to z, type

which returns

The diff function can also take a symbolic matrix as its input. In this case, the differentiation is done element-by-element. Consider the example

which returns

The command

returns

You can also perform differentiation of a column vector with respect to a row vector. Consider the transformation from Euclidean (x, y, z) to spherical coordinates as given by , , and . Note that corresponds to elevation or latitude while denotes azimuth or longitude.

To calculate the Jacobian matrix, J, of this transformation, use the jacobian function. The mathematical notation for J is

For the purposes of toolbox syntax, we use l for and f for . The commands

return the Jacobian

and the command

returns

Notice that the first argument of the jacobian function must be a column vector and the second argument a row vector. Moreover, since the determinant of the Jacobian is a rather complicated trigonometric expression, we used the simple command to make trigonometric substitutions and reductions (simplifications). The section Simplifications and Substitutions discusses simplification in more detail.

A table summarizing diff and jacobian follows.

Mathematical Operator
MATLAB Command

diff(f) or diff(f,x)

diff(f,a)

diff(f,b,2)

J = jacobian([r:t],[u,v])


  Using the Symbolic Math Toolbox Limits