An Introduction to Mathematica
for Calculus I

0. Introduction

This document provides a brief introduction to the Mathematica computer algebra system.  It is intended to serve as a guidline or quick reference for the study of Calculus I using Mathematica.  This is by no means a complete guide to the use of Mathematica.  The discussion of certain commands and topics has been sacrificed for the sake of brevity.  Many commands will be introduced in the projects that will be assigned to you this semester.  For assistance on more advanced topics not discussed here, it is recommended that you use the on-line help.

1. Getting Started

1.  The fact that you are reading this implies that you learned how to launch Mathematica (either by clicking the Mathematica icon on the desktop or launching Mathematica through the start menu).
2.  To print the current worksheet, choose the PRINT option under the FILE menu and click on OK.
3.  To quit Mathematica, you may pull down the FILE menu and click on EXIT.  Be sure that you have saved the file (by pulling down the FILE menu and clicking SAVE or SAVE AS).  You should save new files to your student (NTNET) account or to a personal flash drive.

2. Mathematica Input

By defult, matematica puts new cells in "Input" mode.  To change the mode to "Text" pull down the FORMAT menu, choose STYLE, and click on the TEXT style (or use the shortcut key ALT-7).  Notice that the cells in this worksheet, so far, have used the "Title", "Section", and "Text" styles.

When a cell is in "Input" mode, you may issue a mathematical command by typing the command and then pressing either the SHIFT-ENTER key or the ENTER key on the number pad.  The following cell multiplies 5 times 10.

5*10

In the next cell, two command are issued by separating the commands with a carriage return (a normal ENTER key).

2+5
3+2

If a command ends in a semicolon (;) then Mathematica will not display the output as in the next cell.

a=2; b=3
c=a+b

The percent sign (%) can be used to refer to the preveous output.  Please note that the preveous output is the output to the last command that was issued and not necesarily the value of the preveous cell.

2/5+3/7
%^2

The following is an example of a binomial probability.

7!
%/(2!*5!)
%*.3^2*.7^5

Notice that the following example uses a double percent (%%) to reference the second to the last output.

5!
%/3!
%%/5

Now you try some basic mathematical operations by clicking right below this cell and typing a command.

3. Operators, Constants, and Elementary Functions

The standard arithmetic operations may be performed by using +, -, *, /, and ^.  Mathematica also has built in functions like sin, cos, and log.  In Mathematica the built in functions and commands are case sensitive and use square brackets.  For example

Sin[Pi/3]

is the proper way of issuing the sin command.  Let's look at what happens when we use improper syntax:

sin[Pi/3]

Sin(Pi/3)

Notice that if we forget to capitalize, then Mathematica treats "sin" as an unknown variable.  That is, "sin" is not defined in the Mathematica syntax.  If we use parenthasese instead of square brackets, then Mathematica treats the statement as a multiplication instead of a function evaluation.  Also not the use of capitalization in "Pi".  Let's see what happens if we forget to use capitalization here:

Sin[pi/3]

Mathematica treats "pi" as an unknown variable, not the number.  Some of the other common constants and symbols are "I" for the imaginary number (Sqrt[-1]), and using the function "Exp" we can get the e by "Exp(1)".  Note that Mathematica has a PALETTES menu.  In this menu there is a BASIC MATH ASSISTANT palet.  Open this palet to see a way to enter common numbers, symbols, constants (like π, i, and e) and operators.  The following example uses the BASIC MATH ASSISTANT palet

Cos[π]
Log[(Sqrt[E])]
Log10[100]

A few usefull Mathematica functions are "N" and "Simplify".  N[x] or x//N will give a floating point approximation to the number x.  "Simplify" will attept to rewrite an expression into a reduced mathematical form.

N[(Sqrt[2])]
π+E//N
Simplify[x^2+3(x-1)^2]

4. Editing Commands in Mathematica Sessions

Because Mathematica is used interactively, the abilit5y to edit commands and then reissue them is a skill worth acquiring.  To explain, suppose you issue the command

N[(Sqrt[2])/2]

After realizing that your answer is approximate to 6 significant digits, you decide that you want your answer approximated to 10 digits.  In the "N" command there is an optional parameter that attempts to give a result acuate to a specified precision.  To get your desired result you can do either of the following: 1) retype a completely new command ("N[(Sqrt[2])/2, 10]") or 2) click in the cell you just executed and make the desired modifications.  Try the second method in the above cell, then try the first method by clicking right below this text and issuing a new command.

5. Online Help

If you have a question about a Mathematica command, you can use the online help facility.  Pull down the HELP menu and use the DOCUMENTATION CENTER to explore the commands "N" and "Expand".  Use what you learn to multiply out the expression (((x-1))^5) in a cell below this text.

6. Defining Variables

You may assign a value or expression to a variable with the equal symbol (=).

a=5
a^2
b=x^2+a*x+2a
Solve[b-4==0,x]

Once a variable has been asigned, you may want to reuse that variable name without keeping the assigned value.  To unassign a value you can use the "Clear" command.

Clear[a]
b=x^2+a*x+2a

7. Algebra

One of the primary benefits of Mathematica is that it allows you to algebraically manipulate symbolic expressions.  Some of the useful algebraic commands are: "Simplify" (simplifies an algebraic expression), "Expand" (expands an expression), "Replace", "With", and /. (substitutes values), "Factor" (factors a polynomial), and "Solve" (solves an expression for a specified variable).  What follows are several examples that illustrate some of the algebraic commands.

Expand[(x^2+1)(x-3)(x-1)]

Factor[%]

h=%

h/.{x->2}

f[x_]:=With[{z=x^2+2x+3},z^2-z+5]
f[a]

Recall that we had assigned a value to "b", so we will now clear that value.

Clear[b]

Now we can use "b" in another command as an unassigned variable.

Replace[x^2+2x,x->a+b,{2}]
Simplify[%]

sols=Solve[x^2+5x+3==0,x]

We can use the values by using the substitution commands and reference individual parts as follows.

N[ x/.sols ]
x/.sols[[1]]//N

8. Functions and Expressions

In Mathematica you can work with the expression 3x+1 in a couple of different ways.  First as an expression:

f=3x+1

Then to substitute the value 2 in for x we do the following

f/.{x->2}

Secondly, we can define a Mathematica function as follows and use function notation to evaluate the function at 2:

Clear[f]

f[x_]:=3x+1
f[2]

9. Graphics

Along with the ability of performing algebraic manimulation, Mathematica shows it's true value when you wish to graphically display results.  There are multitude of ways of generating graphics in Mathematica, but the most basic technique is the use of the "Plot" command.  What follows are several examples that illustrate the use of the "Plot" command and some of it's options.

Plot[Sin[x],{x,0,2π}]

Plot[Sin[x],{x,0,2π},
   Ticks->{{π/2,π,3π/2,2π},{-1,1}},
   AxesLabel->{x,y}]

Plot[((Sin[x^2])/(x^2+1)),{x,0,10}]

Plot[((Sin[x^2])/(x^2+1)),{x,0,10},PlotRange->All]

See the online help for a full list of the options that "Plot" command can use.