Tutorial 10:  Calculus

by R. Dover, IMSA

Naturally, Mathematica is pretty good at calculus.  We'll begin with limits.  For the most part, the examples are self-explanatory.  Create your own problems and examples as you go.  (Note that this notebook is optional.)

Limits

Limit[Sin[x]/x,  x -> 0]

Limit[((2  (x^3) - 4  x)/((x^3) + 1)),  
      x ->  ∞]

Remember that one can use the word "Infinity" instead of the symbol.  (This is not to suggest that's better, but it is to remind you that it's an option.)  
	The notation for one-sided limits may be a little confusing, given the usual \(TraditionalForm\`x -> \(a\^+\)\)or \(TraditionalForm\`x -> \(a\^-\)\)notation seen in books and hand-written work.  When we write \(TraditionalForm\`x -> \(a\^+\)\), x is coming from the right, going left. Hence, it is moving in a negative direction and Mathematica uses "Direction-> -1."  Similarly, for \(TraditionalForm\`x -> \(a\^-\)\), x is coming from the left, moving in a positive direction, so we use "Direction-> 1."

Limit[1/x,  x -> 0,  Direction -> 1]

Limit[1/x,  x -> 0,  Direction -> -1]

Here's a different type - which should be recognizable.

Limit[((Tan[x + h] - Tan[x])/h),  h -> 0]

Though this is certainly accurate, see the next section for more direct methods.

Derivatives

Be sure to indicate the variable in each case.  (Note that this is one of the few cases where Mathematica does not require the full English word for the command.)

D[x Log[x],  x]

Find the next derivative and then simplify the result to see the more familiar form.

D[f[x]/g[x],  x]

D[-(1/2) g (t^2) + (Subscript[v, 0]) t  +  (Subscript[s, 0]),  t]

To find the third derivative, (((d^3) y)/(dx^3)), the coding at the end changes as follows.

D[Tan[x],  {x,  3}]

Alternatively, once can define a function first and then use more standard notation.

f[x_] := Sin[Sin[Sin[x]]]

f'[x]

f''[x]

On the palette, for the familiar derivative in single-variable calculus, use (∂_□) □.

(∂_x) ArcTan[x]

For multivariable functions, use \(TraditionalForm
      \`∂\_\(□, □\)□\).  Note that the parentheses are necessary.

(∂_(x, y))((x^3) (y^4))

Implicit functions

Implicitly-defined functions require some special care.  First, we'll name our equation.

equat1  =  (x^3) -  4 x y  +  (y^2) == 12

We can't take a derivative with respect to x yet, since Mathematica would interpret y as a constant.  We must first express y as f[x].

equat1 /. y -> f[x]

Then differentiate and solve for f'[x].

D[%, x]

Solve[%,  f'[x]]

A max-min problem

Consider the function y = cos(x) over the interval (-π/2, π/2).  Find the area of the largest rectangle which may be constructed with two vertices on the x-axis and the other two vertices on the graph of the function.

First, we'll draw a picture to help understand the problem a little better, beginning with the graph of cos(x).

grcosx  =  Plot[Cos[x],  {x,  -2,  2}]

The next group of commands give something new.  We construct a typical rectangle and then show the rectangle and the graph together.

Needs["Graphics`Master`"];
rect  =  {GrayLevel[ .5], 
          Rectangle[{-1.1, 0}, {1.1,  Cos[1.1]}]};
Show[{Graphics[rect],  grcosx},  Axes  ->  True]

We now define the area function, where the base is 2x and the height is Cos[x].

areaofrect[x_] := 2  x Cos[x]

Find the derivative, and solve for the stationary point. Here, the FindRoot command will be appropriate.

FindRoot[areaofrect'[x] == 0,  {x,  1}]

Substitute this value of x to find the area.

areaofrect[x] /. %

Integrals

Integrate[x^3 Cos[x],  x]

∫(1/((x^4) + 1)) \[DifferentialD]x

As before, the command may be entered in the "old" way or using the palette.  As you would expect, Mathematica will integrate lots of functions, but there are some which can't be done.  It's not that Mathematica can't handle them; they just don't have elementary antiderivative formulas.  Check these out.

∫Sin[Sin[x]] \[DifferentialD]x

∫Sin[t]/t \[DifferentialD]t

Definite integrals may be done exactly or approximately, with choices of notation.

(∫_3^5)(( x + 1)/((x^2) - 
              4)) \[DifferentialD]x

Integrate[(x +  1)/(x^2 - 4),  {x,  3,  5}]

NIntegrate[(x +  1)/(x^2 - 4),  {x,  3,  5}]

Note that if  N[  ]  is used around the symbolic integral sign, then Mathematica first tries to integrate exactly if possible.  Using NIntegrate may be faster.  
	Improper integrals may be done as well. (Note: Sometimes "∞" shows as a small black rectangle.)

(∫_1^∞) 1/(x^3) \[DifferentialD]x

Or perhaps we should consider the Fundamental Theorem and look at a plot and a derivative  related to this.

Plot[(∫_0^x) Cos[t] \[DifferentialD]t,  {x,  0,  
        2  π}]

(∂_x) (∫_0^x) Cos[
            t] \[DifferentialD]t

Series

The Taylor series in x about a = 0 of degree 6 for  (e^x) is found by the following coding.

Series[(E^x),  {x,  0,  6}]

The O[x]^7represents the error or remainder.  To eliminate this (before graphing or using the polynomial in some other way), use the "Normal" command.

Normal[%]

Find several terms of the series for Sin[x].  Plot the polynomial and Sin[x] together in different colors.

Differential equations

As with implicit derivatives, be sure to indicate that y is a function of x by using y[x].  To solve y'' - y' - 6y = x, execute the following.

DSolve[y''[x] - y'[x] - 6  y[x] == x,  y[x],  
      x]