Symbolic Math Toolbox    

Extended Calculus Example

The function

provides a starting point for illustrating several calculus operations in the toolbox. It is also an interesting function in its own right. The statements

store the symbolic expression defining the function in f.

The function ezplot(f) produces the plot of as shown below.

The ezplot function tries to make reasonable choices for the range of the x-axis and for the resulting scale of the y-axis. Its choices can be overridden by an additional input argument, or by subsequent axis commands. The default domain for a function displayed by ezplot is . To produce a graph of for , type

Let's now look at the second derivative of the function f:

Equivalently, we can type f2 = diff(f,x,2). The default scaling in ezplot cuts off part of f2's graph. Set the axes limits manually to see the entire function:

From the graph, it appears that the values of lie between -4 and 1. As it turns out, this is not true. We can calculate the exact range for f (i.e., compute its actual maximum and minimum).

The actual maxima and minima of occur at the zeros of . The statements

compute and display it in a more readable format:

We can simplify this expression using the statements

Now use the solve function to find the zeros of .

returns a 5-by-1 symbolic matrix

each of whose entries is a zero of : The commands

convert the zeros to double form:

So far, we have found three real zeros and two complex zeros. However, a graph of f3 shows that we have not yet found all its zeros:

This occurs because contains a factor of , which is zero at integer multiples of . The function, solve(sin(x)), however, only reports the zero at x = 0.

We can obtain a complete list of the real zeros by translating zr

by multiples of :

Now let's plot the transformed zr on our graph for a complete picture of the zeros of f3:

The first zero of found by solve is at x = 0. We substitute 0 for the symbolic variable in f2

to compute the corresponding value of :

A look at the graph of shows that this is only a local minimum, which we demonstrate by replotting f2:

The resulting plot

indicates that the global minima occur near and . We can demonstrate that they occur exactly at , using the following sequence of commands. First we try substituting and into :

The result

shows that and happen to be critical points of . We can see that and are global minima by plotting f2(-pi) and f2(pi) against f2(x).

The actual minima are m1, m2

as shown in the following plot.

The foregoing analysis confirms part of our original guess that the range of is [-4, 1]. We can confirm the other part by examining the fourth zero of found by solve. First extract the fourth zero from z and assign it to a separate variable

to obtain

Executing

displays the zero's corresponding numeric value:

Plotting the point (s, f2(s)) against f2, using

visually confirms that s is a maximum.

The maximum is M1 = 1.0051.

Therefore, our guess that the maximum of is [-4, 1] was close, but incorrect. The actual range is [-4, 1.0051].

Now, let's see if integrating twice with respect to x recovers our original function . The command

returns

This is certainly not the original expression for . Let's look at the difference .

We can simplify this using simple(d) or simplify(d). Either command produces

This illustrates the concept that differentiating twice, then integrating the result twice, produces a function that may differ from by a linear function of .

Finally, integrate once more:

The result

involves the arctangent function.

Though is the antiderivative of a continuous function, it is itself discontinuous as the following plot shows.

Note that has jumps at . This occurs because is singular at .

In fact, as

shows, the numerical value of atan(tan(x))differs from x by a piecewise constant function that has jumps at odd multiples of .

To obtain a representation of that does not have jumps at these points, we must introduce a second function, , that compensates for the discontinuities. Then we add the appropriate multiple of to

and plot the result:

This representation does have a continuous graph.

Notice that we use the domain [-6.28, 6.28] in ezplot rather than the default domain . The reason for this is to prevent an evaluation of

at the singular points and where the jumps in F and J do not cancel out one another. The proper handling of branch cut discontinuities in multivalued functions like arctan x is a deep and difficult problem in symbolic computation. Although MATLAB and Maple cannot do this entirely automatically, they do provide the tools for investigating such questions.


  Taylor Series Simplifications and Substitutions