Mathematica: Calculus 213 Introduction To Mathematica and Mathcad
Mathematica: Calculus 213 Introduction To Mathematica and Mathcad
Mathematica
1. TO BEGIN
Open Mathematica. The first time Mathematica runs, it needs to load the
“kernel”. This takes a minute or so.
There are numerous manuals available in the computer lab to help you.
Mathematica: A System for Doing Mathematics by Computer
Mastering Mathematica
Mathematica by Example
The Mathematica Handbook
Guide to Standard Mathematica Packages
Programming in Mathematica
Differential Equations in Mathematica
3. IMPORTANT NOTES
1
4. TO DEFINE FUNCTIONS
1− x
TO DEFINE: f ( x ) = 3x 2 + 2x − 4 , g ( x ) = , and F ( x ) = sin x ,
1+3 x
Since you have already defined f(x), g(x), and F(x), we will work with them.
6. TO GRAPH FUNCTIONS
TRY: Graphing y = ln(x), y = ln(x – 2), and y = ln(x + 5) on the same axes.
Careful! Mathematica doesn’t understand ln(x). See page 1.
2
Type: Plot3D[Sin[xy], {x,0,3}, {y,0,3}] and press SE.
Why is Mathematica saying it can’t do this? Change xy to x*y and
try it again.
Now look again at this graph with an expanded domain for x and y.
7. TO DIFFERENTIATE
TYPE: D[x^4, {x, 2}] and press SE. (This will give the second
derivative of x4 with respect to x.)
ln(sin x )
Find the third derivative of y = . Be very careful with parentheses,
1 + ex
square brackets, and how you enter ex (use on-line help or review one of the
above examples).
Mathematica has two ways in which you can tell it to perform integration. You
can use the “Integrate” command, or you can use the mouse to construct the integral.
Both methods are shown in the following example.
∫
x2
Example 1. An integral Mathematica can evaluate: dx .
x3 + 1
Log [x3 + 1]
The output Mathematica gives is . You must add C.
3
Log is base e.
3
Method 2: Look over to the right side of the computer screen. Click the mouse
on the button containing ∫ dl . That action should put the integral symbol in
your Mathematica workspace.
x2
Type 3 in for the integrand (to get the fraction, press C / or else use the
x +1
palette, to get up into the exponent area press C 6).
Type x in the little box after the dl.
Log [x3 + 1]
Press SE. Again, the output Mathematica gives is . You
3
must add C. Log is base e.
Whenever Mathematica gives back the same thing you typed in, it means
Mathematica could not evaluate it.
∫e
x2
Example 3. An integral evaluated to a special function: dx .
Sqrt[Pi] Erfi[x]
The output is . So what the ##*%**!! does Erfi mean?
2
For help, Type: ?? Erfi and press SE. Mathematica will tell you a little
about Erfi. Look in a text on complex analysis for more information. This type
of an answer means Mathematica couldn’t come up with an elementary solution.
π
Example 1. A simple definite integral: ∫ sin 2 x dx .
0
Type “Integrate[Sin[x]^2, {x, 0, Pi}]”, or use the palette, and press SE.
4
Pi
The output is .
2
2π
Example 2. An integral with a more complicated solution: ∫ sin x dx .
0
2
Pi
The output is Sqrt[ ] FresnelS[2 Sqrt[2 Pi]]. This is a solution
2
which is given in terms of the special function FresnelS. Probably not very
helpful. See below to get a numerical value for this quantity.
N[%%%] will evaluate the third to the last output, and so on.
π
Example 1. ∫ sin(sin x ) dx .
0
5
The output, after Mathematica loads some special integration packages, is
Integrate[Sin[Sin[x2]], {x, 0, Pi}]. Since this is the same as
your input, it means that Mathematica could not evaluate it.
∫
2
x 2 sin x
Example 2. dx .
0 sin x + cos x
5π
∫
6
x 2 sin x
Example 3. An integral which might not converge: dx .
0 sin x + cos x
Using NIntegrate for this integral gives –4.24134, but Mathematica also gives a
warning that the value is possibly incorrect. If you plot the function, you will see
it has a vertical asymptote in the interval and is an improper integral.
6
Mathcad
1. START-UP AND ARITHMETIC
Start Mathcad. Close the Tip-of-the-Day box (if it pops up) and then close the
Mathcad Resource Center.
To use Mathcad, click your mouse anywhere in the work area. The little red
crosshair is where your typing will appear.
Type: 5 + 6 =
Type: 100/5 = (use the right arrow to get out of the denominator)
2. A LITTLE ALGEBRA
Use your mouse to highlight the entire polynomial, then go up to Symbolics and
click Factor. That should factor your polynomial. If you go to Symbolics and
Expand, it will multiply out the factors. Factored form should be ( x − 1)( x 2 + 4 x + 1) .
3. FUNCTIONS
To define functions (or anything else), Mathcad does not use the equal sign.
Instead, it uses := . To define f ( x) = 3 x + 6 ,
You do not need to type the equal sign. As soon as you type the colon, Mathcad knows
you also want the equal sign so it automatically includes it.
7
Suppose you want to find the value of f (x) for x every integer from 1 to 9. Type
a : 1 ; 9. The colon puts in := and the semicolon puts in the .. to indicate that you want a
list of numbers. Finally, somewhere that is BELOW the definitions of f (x) and a, type
in a = and then type in f(a) =. Working with lists in Mathcad is relatively easy.
Mathcad only knows about definitions in the region BELOW where you typed the
definition. Anywhere ABOVE your definition, Mathcad thinks the definition hasn’t been
provided yet.
Define g ( x) = sin πx . <Ctrl><Shift> P will type pi, or you can click π on the
Greek palette. Did you remember to use : instead of = and remember to enclose the
argument in parentheses? Let’s find the value of g(x) for x = 1, 2, 3, 4, 5, 6.
Type a : 1 ; 6.
Now click anywhere ABOVE your definition of g(x) and type g(a) = . Mathcad
tells you g is not defined. Click and drag the g(a) box down BELOW your definitions so
Mathcad knows what to use for g(x) and a.
5. DIFFERENTIATION
If the Calculus and Evaluation palettes aren’t open, go to View, Toolbars, and
then click the Calculus and Evaluation checkboxes.
x3 − 4
Define f ( x) = . (To get the fraction format, type the / symbol on your
x+2
keyboard BEFORE typing the numerator.)
BELOW your definition of f(x), press the question mark key on your keyboard.
That will put the Leibnitz notation differentiation operator in your work area. (The
reason Mathcad uses the question mark key is because it is really the <Shift> / key.
Leibnitz notation looks like a fraction and / is used for fractions, so <Shift> / is just the
modified fraction for Leibnitz notation.)
Instead of typing <Shift> /, you can also click on the differentiation operator on
the Calculus palette. If you hover the cursor above the button on the palette, Mathcad will
tell you the keyboard short cut: Shift + / means <Shift> /.
Type f(x) in the differentiation sign and then put an x in the bottom of the
operator. (See below.)
8
put f(x) here
d
d
put x here
Do not use the equal sign to evaluate this. Instead, you must put an “Evaluate
Symbolically” arrow, “→”, after the derivative. It is on the evaluation palette. (The
keyboard shortcut for it is <Ctrl> <period>. The period key has the > symbol with it,
which is kind if like the head of an arrow.) Press <Enter> to get the derivative. You
should get:
d
f ( x) → 3⋅
2
x
−
(3 )
x −4
dx ( x + 2) 2
( x + 2)
Integration, both definite and indefinite, are also accomplished by selecting the
appropriate symbol from the Calculus Palette, typing in the function, the variable, and the
limits of integration. Then use the “Evaluate Symbolically” arrow and press <Enter>.
Integrating f(x) with respect to x, you should get:
⌠ 1 3 2
f ( x) d x → ⋅ x − x + 4⋅ x − 12⋅ ln( x + 2)
⌡ 3
6. GRAPHING
Type f(x) along the y-axis and type x along the x-axis as shown below.
9
Type f(x) here.
Type x here.
Click anywhere outside the graphing box, and you should see a red sine wave. Change
the graphing window so that it goes from x = –4 to x = 4 by changing the –10 and the 10.
Next, to plot more than one function on the same graph, put a comma after f(x)
and then type g(x) right below the f(x). You should now have a graph like the one below.
1
1
f ( x)
0
g( x)
−1 1
0
−4 x, x 4
To graph polar functions, define r (t ) = 1 − 2 cos(t ) , insert a Polar Plot instead of
an X-Y Plot, and then put t at the bottom and r(t) at the left. You should get a limaçon as
follows:
90
120 60 3
3
150 2 30
1
r( t ) −3
180 0 0 3.63×10
210 330
240 300
270
t
To graph Parametric plots, define x(t) = sin(3t) and y(t) = cos(5t). Insert an X-Y
Plot and type y(t) on the left and x(t) on the bottom (type them in the placeholders). You
should get the Lissajous figure below.
10
1
1
y ( t) 0
−1 1
1 0 1
−1 x( t ) 1
Now click anywhere on the graph and drag to see the surface rotate.
Click on the f, put a comma and g after it. You should have two surfaces. Click
and drag if you wish. To change the appearance of the surfaces, double click on them and
select the “Appearance” tab. Under “Fill Options,” click “Fill Surface” and “Color Map.”
Under “Line Options,” increase the weight to 1.1 and click “Apply.” Do the same under
the “Plot 2” tab, then click “OK.” Click and drag to rotate the surfaces.
8. SOLVING EQUATIONS
To let Mathcad know that you are working with an equation that you will want it
to solve, you have to use a special equal sign. Use <Ctrl> = instead of just = . For
example, to solve 0 = x 2 − 7 x + 12 , type it in using <Ctrl> =, then use your mouse or
11
keyboard arrows to get the editing lines on the variable (either the x or x2 ). To solve, go
up to Symbolics, Variable, Solve.
1. Factor:
a) 6 x 3 + 29 x 2 − 17 x − 60 b) x 5 − 3 x 4 − 23 x 3 + 51x 2 + 94 x − 120
2. Graph:
a) f ( x) = e x sin( x)
b) x(t ) = t + 1, y (t ) = t 3 − 3t (change graphing window to − 1 ≤ x ≤ 5, − 3 ≤ y ≤ 3 )
c) r (θ ) = θ + θ sin(θ )
d) f ( x, y ) = sin( x) + cos( y )
3. Let f ( x) = e 2 x sin x .
a) find the third derivative of f (x) . solution: 2⋅ exp( 2⋅ x) ⋅ sin ( x) + 11⋅ exp( 2⋅ x) ⋅ cos ( x)
⋅ exp ⋅ π ⋅ 2 + + C
π /4 1 1 1
b) find
∫ f ( x) dx . solution:
0
10 2 5
12