Calculus III, Lab One

Problem 0:  Introduction to Mathematica

 

Directions:  Read and complete the exercises in the following Mathematica Tutorial.  This should get you familiar with the basics you will need for the next three problems.  There is no need to include a write up of Problem 0.  You may include brief general comments about Problem 0 in the conclusion if you wish.

What is Mathematica?

Mathematica is a mathematical software package widely used in education, research and in the industry all over the world. Mathematica can work symbolically, which means that it can find exact solutions, as opposed to approximate numerical (decimal) solutions. It has many built in functions to allow you to solve a wide array of mathematical problems.  Mathematica also has powerful graphics capabilities.

 

Where to find Mathematica

Mathematica is available in many computer labs on campus.  The undergrad computer lab, ECCR 143 is one of these labs.  The other labs in the engineering center also have Mathematica loaded on their computers.  On PCs, you can run Mathematica by opening the "Start" menu and running it from the list of programs.  You can find other ITS labs with Mathematica by looking on the ITS Web Page.


Getting started with Mathematica

Once you have started Mathematica, it will automatically open a blank "notebook".  The notebook is your interface to Mathematica, where you will type in functions as input and receive the answers as output.  If you save a Mathematica session, on PCs the file extension will be "*.nb".

When you begin to type in a notebook, your typing appears in a "cell".  Cells can be formatted in different ways.  "Input" cells are the default.  This is the "Style" (format) you will use to input functions and equations that you want Mathematica to evaluate.  Other types of styles include "Text", which allows you to add comments is your notebook, as well as "Title", "Subtitle", and other text formats to allow you to perform rudimentary word processing in Mathematica.  However, it is not recommended that you use Mathematica to produce your entire lab write-up, as the word processing features are not very advanced. 

To change a cell's style, select the bracket or "handle" at the right of the cell to select it, then open the "Format" menu and select "Style".  You will see a list of styles to choose from.  Be careful - if you want Mathematica to evaluate a formula, the cell that contains the formula must have the "Input" style only, do not mix styles within one cell.

Before you start to use Mathematica, learn the following four rules:

1)  To evaluate input, press SHIFT and ENTER simultaneously.

2) Built in function, such as sin(x), cos(x) and exp(x), always start with a CAPITAL letter.  Mathematica is case sensitive!

3) Constants such as e and pi must be typed into Mathematica as E and Pi. Notice the capital letters!

4) Any argument of a functions must be put within square brackets [ ].  For example, the functions sin(x), cos(x) and exp(x) are entered in Mathematica as Sin[x], Cos[x] and Exp[x].

Mathematica has an extensive help function that you can refer to.  Access help by selecting "Help", "Help Browser" and typing in the command or function you are curious about.

Below follows a table with the syntax for the most common operations and functions:

 

Operation, function or constant

Mathematica command

+ (addition)

+

- (subtraction)

-

X (multiplication)

*

/ (division)

/

the power operator

^

| x | (absolute value of x)

Abs[x]

the square root of x

Sqrt[x]

ex

Exp[x]

ln x (natural logarithm of x)

Log[x]

log10 x (base 10 logarithm of x)

Log[10,x]

sine x

Sin[x]

cosine x

Cos[x]

tangent x

Tan[x]

cotangent x

Cot[x]

arcsine x

ArcSin[x]

arccosine x

ArcCos[x]

arctangent x

ArcTan[x]

arccotangent x

ArcCot[x]

e

E

pi

Pi

The parentheses () are used to group expressions together. It is a common mistake to confuse the usage of parentheses () and square brackets []. The following examples illustrate how they should be used. Study the example carefully and make sure you understand when to use parentheses and when to use square brackets.

 

Example 1
 

(You do not have to type these commands in Mathematica, just read the example and make sure you understand the usage of () and [].)
 

The expression (x+y)2 is entered in Mathematica as

(x+y)^2

The expression sin(x+y) is entered in Mathematica as

Sin[x+y]

The expression sin(3(x+y)2) is entered in Mathematica as

Sin[3*(x+y)^2]



In case you want the numerical value of an expression, use the command N[]. For example, N[Pi-3] returns 0.141563.

Exercise 1


Using Mathematica, compute:

a)  3sin(pi) - Type in 3*Sin[Pi] and hit Shift-Enter.

b)  1+1+1/2+1/6+1/24-e

c)  ln(1000+2pi-2)

d)  ei*pi  -  Here i denotes the so-called imaginary number "the square root of -1". The number i is entered in Mathematica as I. The answer you will get has been called "the most beautiful result in mathematics".

e)  The number of combinations in which 12 persons can stand in line. - Hint:  This one requires knowledge about factorials. If you know this, try to solve the exercise. Factorials in Mathematica are obtained by typing ! )


Plotting functions of the type f(x)

The syntax to plot a function f(x) is given below.


Plot[f(x), {x,xmin,xmax} ]


Here x refers to the variable of the function. xmin and xmax refers to the lower and the upper limit of the domain respectively. To enlarge a graph, simply click on the graph and drag the black boxes to obtain a suitable size.  You can copy and paste cells from Mathematica to include them in a Word document.

Exercise 2
 

a)  In Mathematica, plot the function tan(x) from x = -10 to x = 10 by entering

Plot[Tan[x],{x,-10,10}]

b)  Now change the plot range so that it plots using the range f(x) = -5 to f(x) = 5 by adding an "Option" to the plot command. To change the plot range, use the option PlotRange.  Run the following command:

Plot[Tan[x],{x,-10,10}, PlotRange -> {-5, 5}]

c)  Finally, add axes labels and a title to the graph. This is done by adding the options AxesLabel and PlotLabel to the plotting command.

Plot[Tan[x], {x,-10,10}, PlotRange->{-5,5}, AxesLabel->{"x","y"}, PlotLabel->"my plot"]

Created by Kristian Sandberg
Department of Applied Mathematics
University of Colorado at Boulder

Modified by David Beltran-del-Rio