| Symbolic Math Toolbox | ![]() |
Extended Calculus Example
This section presents an extended example that illustrates how to find the maxima and minima of a function. The section covers the following topics:
Defining the Function
The starting point for the example is the function
You can create the function with the commands
The example shows how to find the maximum and minimum of the second derivative of
. To compute the second derivative, enter
Equivalently, you can type f2 = diff(f,x,2). The default scaling in ezplot cuts off part of the graph of f2. You can set the axes limits manually to see the entire function:
From the graph, it appears that the maximum value of
is 1 and the minimum value is -4. As you will see, this is not quite true. To find the exact values of the maximum and minimum, you only need to find the maximum and minimum on the interval
. This is true because
is periodic with period
, so that the maxima and minima are simply repeated in each translation of this interval by an integer multiple of
. The next two sections explain how to do find the maxima and minima.
Finding the Zeros of f3
The maxima and minima of
occur at the zeros of
. The statements
compute
and display it in a more readable form:
3 sin(x) sin(x) cos(x) sin(x) 384 --------------- + 96 --------------- - 4 --------------- 4 3 2 (5 + 4 cos(x)) (5 + 4 cos(x)) (5 + 4 cos(x))
You can simplify this expression using the statements
f3 = simple(f3); pretty(f3) 2 2 sin(x) (96 sin(x) + 80 cos(x) + 80 cos(x) - 25) 4 ------------------------------------------------- 4 (5 + 4 cos(x))
Now, to find the zeros of
, enter
This returns a 5-by-1 symbolic matrix
zeros =[ 0][ atan((-255-60*19^(1/2))^(1/2),10+3*19^(1/2))][ atan(-(-255-60*19^(1/2))^(1/2),10+3*19^(1/2))][ atan((-255+60*19^(1/2))^(1/2)/(10-3*19^(1/2)))+pi][ -atan((-255+60*19^(1/2))^(1/2)/(10-3*19^(1/2)))-pi]
each of whose entries is a zero of
. The commands
convert the zeros to double form:
So far, you have found three real zeros and two complex zeros. However, as the following graph of f3 shows, these are not all its zeros:
ezplot(f3) hold on; plot(zerosd,0*zerosd,'ro') % Plot zeros plot([-2*pi,2*pi], [0,0],'g-.'); % Plot x-axis title('Graph of f3')
The red circles in the graph correspond to zerosd(1), zerosd(4), and zerosd(5). As you can see in the graph, there are also zeros at
. The additional zeros occur because
contains a factor of
, which is zero at integer multiples of
. The function, solve(sin(x)), however, only finds the zero at x = 0.
A complete list of the zeros of
in the interval
is
You can display these zeros on the graph of
with the following commands:
ezplot(f3) hold on; plot(zerosd,0*zerosd,'ro') plot([-2*pi,2*pi], [0,0],'g-.'); % Plot x-axis title('Zeros of f3') hold off;
Finding the Maxima and Minima of f2
To find the maxima and minima of
, calculate the value of
at each of the zeros of
. To do so, substitute zeros into f2 and display the result below zeros:
has an absolute maximum at
, whose value is 1.0051.
has an absolute minimum at
, whose value is -4.
has a local minimum at
, whose value is 0.0494.
You can display the maxima and minima with the following commands:
clf ezplot(f2) axis([-2*pi 2*pi -4.5 1.5]) ylabel('f2'); title('Maxima and Minima of f2') hold on plot(zeros, subs(f2,zeros), 'ro') text(-4, 1.25, 'Absolute maximum') text(-1,-0.25,'Local minimum') text(.9, 1.25, 'Absolute maximum') text(1.6, -4.25, 'Absolute minimum') hold off;
This displays the following figure.
The preceding analysis shows that the actual range of
is [-4, 1.0051].
Integrating
To see whether integrating
twice with respect to x recovers the original function
, enter the command
This is certainly not the original expression for
. Now look at the difference
.
You 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
.
involves the arctangent function.
Note that
is not an antiderivative of
for all real numbers, since it is discontinuous at odd multiples of
, where
is singular. You can see the gaps in
in the following figure.
To change
into a true antiderivative of
that is differentiable everywhere, you can add a step function to
. The height of the steps is the height of the gaps in the graph of
. You can determine the height of the gaps by taking the limits of
as x approaches
from the left and from the right. The limit from the left is
On the other hand, the limit from the right is
The height of the gap is the distance between the left and right hand limits, which is
, as shown in the following figure.
You can create the step function using the round function, which rounds numbers to the nearest integer, as follows:
Each step has width
and the jump from one step to the next is
, as shown in the following figure.
Next, add the step function J(x) to F(x) with the following code:
Adding the step function raises the section of the graph of F(x) on the interval
up by
, lowers the section on the interval
down by
, and so on, as shown in the following figure.
When you plot the result by entering
you see that this representation does have a continuous graph.
| Calculus Example | Simplifications and Substitutions | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |