Chapter 1	Introduction

Welcome to Mathematica! This tutorial manual is intended as a supplement to Rogawski's Calculus textbook and aimed at students looking to quickly learn Mathematica through examples.  It also includes a brief summary of each calculus topic to emphasize important concepts.  Students should refer to their textbook for a further explanation of each topic.

1.1  Getting Started

Mathematica is a powerful computer algebra system (CAS) whose capabilities and features can be overwhelming for new users.  Thus, to make your first experience in using Mathematica as easy as possible, we recommend that you read this introductory chapter very carefully.  We will discuss basic syntax and frequently used commands.

NOTE: You may need to obtain a computer account on your school's computer network in order to access the Mathematica software package available on campus computers.  Check with your instructor or your school's IT office.

1.1.1  First-Time Users of Mathematica 7

Launch the program Mathematica 7 on your computer.  Mathematica will automatically create a new Notebook (see typical startup screen below).

1.1.2  Entering and Evaluating Input Commands

Just start typing to input commands (a cell formatted as an input box will be automatically created).  For example, type 3+7.  To evaluate this command or any other command(s) contained inside an input box, simultaneously press SHIFT+ENTER, that is, the keys SHIFT and ENTER at the same time.  Be sure your mouse's cursor is positioned inside the input box or else select the input box(es) that you want to evaluate.  The kernel application, which does all the computations, will load at the first evaluation.  This is a one-time procedure whenever Mathematica is launched and may take a few seconds depending on the speed of your computer, so be patient.

As can be seen from the screen shot above, a cell formatted as an output box and containing the value 10 is generated as a result of the evaluation.  To create another input box (cell), just start typing again and an input box will be inserted at the position of the cursor (use the mouse to position the cursor where you would like to insert the new input box).

1.1.3  Documentation Center (Help Menu)

Mathematica provides an online help menu to answer many of your questions about the program.  One can search for a particular command expression in the Documentation Center under this menu or else just position the cursor next to the expression (for example, Plot) and select Find Selected Function (F1) under the Help menu (see screen shot that follows).

Mathematica will then display a description of Plot, including examples on how to use it (see screen shot below).

For only a brief description of Plot (or any other expression expr), just evaluate ?Plot (or ?expr).

?Plot

1.2  Mathematica's Conventions for Inputting Commands

1.2.1  Naming

Built-in Mathematica commands, functions, constants, and other expressions begin with capital letters and are (for the most part) one or more full-length English words (each word is capitalized).  Furthermore, Mathematica is case sensitive; a common cause of error is the failure to capitalize command names.  For example, Plot, Integrate, and FindRoot are valid function names.  Sin, Exp, Det, GCD, and Max are some of the standard mathematical abbreviations that are exceptions to the full-length English word(s) rule.

User-defined functions and variables can be any mixture of uppercase and lowercase letters and numbers.  However, a name cannot begin with a number.  User-defined functions may begin with a lowercase letter, but this is not required.  For example, f, g1, myPlot, r12, sOLution, and Method1 are permissible function names.

1.2.2.  Parenthesis,  Brackets, and Braces

Mathematica interprets various types of delimiters (brackets) differently.  Using an incorrect type of delimiter is another common source of error.  Mathematica's bracketing conventions are as follows:

1) Parentheses, ( ), are used only for grouping expressions.  For example, (x-y)^2, 1/(a+b) and (x^3-y)/(x+3y^2) demonstrate proper use of parentheses.  Users should realize that Mathematica understands f(2) as f multiplied with 2 and not as the function f(x) evaluated at x=2.

2) Square brackets, [ ], are used to enclose function arguments.  For example, Sqrt[346], Sin[Pi], and Simplify[(x^3-y^3)/(x-y)] are valid uses of square brackets.  Therefore, to evaluate a function f(x) at x=2, we can type f[2].

3) Braces or curly brackets, { }, are used for defining lists, ranges and iterators.  In all cases, list elements are separated by commas.  Here are some typical uses of braces:
{1, 4, 9, 16, 25, 36}: This lists the square of the first six positive integers.
Plot[f[x],{x,-5,5}]: The list {x,-5,5} here specifies the range of values for x in plotting f.
Table[m^3,{m,1,100}]: The list {m,1,100} here specifies the values of the iterator m in generating a table of cube powers of the first 100 whole numbers.

1.2.3.  Lists

A list (or string) of elements can be defined in Mathematica as List[(Subscript[e, 1]),(Subscript[e, 2]),...,(Subscript[e, n])] or {(Subscript[e, 1]),(Subscript[e, 2]),...,(Subscript[e, n])}.  For example, the following command defines S={1,3,5,7,9} to be the list (set) of the first five odd positive integers.

S=List[1,3,5,7,9]

To refer to the kth element in a list named expr, just evaluate expr[[k]].  For example, to refer to the fourth element in S, we evaluate

S[[4]]

It is also possible to define nested lists whose elements are themselves lists, called sublists.  Each sublist contains subelements.  For example, the list T={{1,3,5,7,9},{2,4,6,8,10}} contains two elements, each of which is a list (first five odd and even positive integers).

T={{1,3,5,7,9},{2,4,6,8,10}}

To refer to the kth subelement in the jth sublist of expr, just evaluate expr[[j,k]].  For example, to refer to the third subelement in the second sublist of T (or 6), we evaluate

T[[2,3]]

A detailed description of how to manipulate lists (e.g., to append elements to a list or delete elements from a list) can be found in Mathematica's Documentation Center (under the Help menu).  Search for the entry List.

1.2.4.  Equal Signs

Here are Mathematica's rules regarding the use of equal signs:

1) A single equal sign (=) assigns a value to a variable.  Thus, entering q = 3 means that q will be assigned the value 3.

q=3

If we then evaluate 10+q^3, Mathematica will return 37.

10+q^3

As another example, suppose the expression y = x^2-x-1 is entered.

y=x^2-x-1

If we then assign a value for x, say x=3, then in any future input containing y, Mathematica will use this value of x to calculate y, which would be 5 in our case.

x=3
y

2) A colon-equal sign (:=) creates a delayed statement for an expression and can be used to define a function.  For example, typing f[x_]: = x^2-x-1 tells Mathematica to delay the assignnment of f(x) as a function until f is evaluated at a particular value of x.

f[x_]:=x^2-x-1
f[3]

We will say more about defining functions in section 1.3 below.

3) A double-equal sign (= =) is a test of equality between two expressions.  Since we previously set x = 3, then evaluating x = = 3 returns True, whereas evaluating x = = -3 returns False.

x==3
x==-3

Another common usage of the double equal sign (= =) is to solve equations, such as the command Solve[x^2-x-1= = 0, x] (see Section 1.5).  Be sure to clear the variable x beforehand.

Clear[x]
Solve[x^2-x-1==0,x]

1.2.5.  Referring to Previous Results

Mathematica saves all input and output in a session.  Type In[k] (or Out[k]) to refer to input (or output) line numbered k.   One can also refer to previous output by using the percent sign %.  A single % refers to Mathematica's last output, %% refers to the next-to-last ouput, and so forth.  The command %k refers to the output line numbered k.  For example, %12 refers to output line number 12.

Out[12]

Mathematica saves all input and output in a session.  Type In[k] (or Out[k]) to refer to input (or output) line numbered k.   One can also refer to previous output by using the percent sign %.  A single % refers to Mathematica's last output, %% refers to the next-to-last ouput, and so forth.  The command %k refers to the output line numbered k.  For example, %12 refers to output line number 12.

%12

NOTE: CTRL+L reproduces the last input and CTRL+SHIFT+L reproduces the last output.

1.2.6.  Commenting

One can insert comments on any input line.  The comments should be enclosed between the delimiters (* and *).  For example,

(* This command plots the graph of two functions in different colors. *)Plot[{Sin[x],Cos[x]},{x,0,2Pi},PlotStyle->{Red,Blue}]

NOTE: One can also insert comments by creating a text box.  First, create an input box.  Then select it and format it as Text using the drop-down window menu.

1.3  Basic Calculator Operations

Mathematica uses the standard symbols +, -, *, /, ^, ! for addition, subtraction, multiplication, division, raising powers (exponents), and factorials, respectively.  Multiplication can also be performed by leaving a blank space between factors.  Powers can also be entered by using the palette menu to generate a superscript box (or else press CTRL+6) and fractions can be entered by generating a fraction box (from palette menu or pressing CTRL+/ ).

To generate numerical output in decimal form, use the command N[expr] or N[expr,d].  In most cases, N[expr] returns six digits of expr by default and may be in the form n.abcde *(10^m) (scientific notation), whereas N[expr,d] attempts to return d digits of expr.

NOTE: Mathematica can perform calculations to arbitrary precision and handle numbers that are arbitrarily large or small.

Here are some examples:

Pi

N[Pi]

N[Pi,200]

(6^(5^4))

1/300!

(* This command returns a decimal answer of the last output *)
N[%]

Example 1.1.  How close is (e^((Sqrt[163])π)) to being an integer?

Solution:

E^(Pi*Sqrt[163])

N[%,40]

We can rewrite this output in non-scientific notation by moving the decimal point 17 places to the right.  This shows that (e^((Sqrt[163])π)) is very close to being an integer.  Another option is to use the command Mod[n,m], which returns the remainder of n when divided by m, to obtain the fractional part of (e^((Sqrt[163])π)):

Mod[%,1]

1-%

1.4  Functions

There are two different ways to represent functions in Mathematica, depending on how they are to be used.  Consider the following example:

Example 1.2.  Enter the function f(x)=(((x^2)+x+2)/(x+1)) into Mathematica.

Solution:

Method 1:  Simply assign f the expression (((x^2)+x+2)/(x+1)), for example,

Clear[f,x] (* This clears the arguments f and x *)

f=(x^2+x+2)/(x+1)

To evaluate f(x) at x=10, we use the substitution command /. (slash-period) as follows:

f/.x->10

Warning: Recall that Mathematica reads f(x) as f multiplied by x; commas are considered delimiters.

f(10)

Method 2: An alternative way to explicitly represent f as a function of the argument x is to enter

Clear[f] 
	f[x_]:=(x^2+x+2)/(x+1)

Evaluating the command f[10] now tells Mathematica to compute f at x=10.

f[10]

More generally, the command f[{a,b,c,...}] evaluates f(x) for every value of x in the list {a,b,c,...}:

f[{-3,-2,-1,0,1,2,3}]

Here, Mathematica is warning us that it has encountered the undefined expression (1/0) in evaluating f(-1) by returning the message ComplexInfinity.

Remark: If there is no need to attach a label to the expression (((x^2)+x+2)/(x+1)), then we can directly enter this expression into Mathematica:

(((x^2)+x+2)/(x+1))/.x->10

(((x^2)+x+2)/(x+1))/.x->{-3,-2,-1,0,1,2,3}

Piece-wise functions can be defined using the command If[cond,p,q], which evaluates p if cond is true; otherwise, q is evaluated.

Example 1.3.  Enter the following piece-wise function into Mathematica:

f(x) ={({{tan (((π x)/4)),, if |x|<1;}, {x,, if |x|≥1.}})

Solution:

f[x_]:=If[Abs[x]<1,Tan[Pi*x/4],x]

1.5  Palettes

Mathematica allows us to enter commonly used mathematical expressions and commands from six different palettes.  Palettes are calculator pads containing buttons that can be clicked on to insert the desired expression or command into a command line.  These palettes can be found under the Palettes menu.  If the Basic Math Assistant Palette does not appear by default, then click on Palettes from the menu and select it.  One can also select more advanced math typesetting palettes such as the Basic Math Input and Algebraic Manipulate Palettes.

Example 1.4.  Enter (Sqrt[(3/(π^4))])into a notebook.

Solution:

Here is one set of instructions for entering this expression using the Basic Math Assistant Palette:

a) Click on the palette button (Sqrt[□]).
b) Click on (□/□).
c) Enter the number 3 into the highlighted top placeholder.

(Sqrt[(3/□)])

d) Press the TAB key to move the cursor to the bottom placeholder.
e) Click on (□^□).
f) To insert π  into the base position, click on the palette button for π.

(Sqrt[(3/(π^□))])

g) Press the TAB key to move the cursor to the superscript placeholder.
h) Enter the number 4.

(Sqrt[(3/(π^4))])

1.6  Solving Equations

Mathematica has a host of built-in commands to help the user solve equations and manipulate expressions.  The command Solve[lhs==rhs, var] solves the equation lhs==rhs (recall Mathematica's use of the double-equal sign) for the variable var.  For example, the command below solves the quadratic equation (x^2)-4=0 for x.

Solve[x^2-4==0,x]

A system of m equations in n unknowns can also be solved with using the same command, but formatted as Solve[{(Subscript[lhs, 1])==(Subscript[rhs, 1]),(Subscript[lhs, 2])==(Subscript[rhs, 2]),...,(Subscript[lhs, m])==(Subscript[rhs, m])},{(Subscript[x, 1]),(Subscript[x, 2]),...,(Subscript[x, n])}].  In situations where exact solutions cannot be obtained (e.g., certain polynomial equations of degree 5 or higher), numerical approximations can be obtained through the command NSolve[lhs==rhs,var].  Here are two examples:

Clear[x,y]
Solve[{2x-y==3,x+4y==-2},{x,y}]

NSolve[x^5-x+1==0,x]

There are many commands to algebraically manipulate expressions: Expand, Factor, Together, Apart, Cancel, Simplify, FullSimplify, TrigExpand, TrigFactor, TrigReduce, ExpToTrig, PowerExpand, and ComplexExpand.

Factor[x^2+4x-21]

NOTE: These commands can also be entered from the Algebraic Manipulation Palette; highlight the expression to be manipulated and click on the button corresponding to the command to be inserted.  The screen shot below demonstrates how to select the Factor command from the Algebraic Manipulate Palette to factor the highlighted expression (x^2)+4x-21.

Exercises

In Exercises 1 through 5, evaluate the expressions:
1. 103.41+20*76	2. (((5^2)+π)/(1+π))	 	3. (1/(1+(1/(1+(1/(4!))))))	 4. ((2.06*(10^9))/(0.99*(10^(-8))))		5. What is the remainder of 1998 divided by 13?

In Exercises 6 through 8,  enter the functions into Mathematica and evaluate each at x=1:
6. f(x)=2(x^3)-6(x^2)+x-5		7. g(x)=(((x^2)-1)/((x^2)+1))		8. h(x)=|(Sqrt[x])-3|

In Exercises  9 through 11, evaluate the functions at the given point using Mathematica:
9. f(x)=1001+(x^4) at x=25		10. 1+(Sqrt[x])+(x^(1/3))+(x^(1/4)) at x=π	11. 1+(1/(2+((((2x+1))^2)/(2+((((4x+1))^2)/2))))) at x=1

In Exercises 12 through 17, enter the expressions into Mathematica:

12. (80^(1/3))		13. ((1024^(1/5))/(2^(-3)))			14. ((Sqrt[125])^(1/3))
15. (Sqrt[((10(a^7)b)^(1/3))])	16. ((((((x^(-3))(y^4))/5)))^(-3))		17. (((((3(m^(1/6))(n^(1/3)))/(4(n^(-(2/3)))))))^2)

In Exercises 18 through 21, expand the expressions:

18. (x+1)(x-1) 		19. (x+y-2)(2x-3)		20. ((x^2)+x+1)(x-1)		21. ((x^3)+(x^2)+x+1)(x-1)

In Exercises 22 through 25, factor the expressions:

22. (x^3)-2(x^2)-3x		23. 4(x^(2/3))+8(x^(1/3))+3.6		24. 6+2x-3(x^3)-(x^4)		25. (x^5)-1

In Exercises 26 through 29, simplify the expressions using both of the commands Simplify and FullSimplify (the latter uses a wider variety of methods to simplify expressions).

26. (((x^2)+4x-12)/(3x-6))			27. ((((2/x)-3))/(1-(1/(x-1))))			28. (((x(1-2x)))^(-3/2))+(((1-2x))^(-1/2))		29. (((x^5)-1)/(x-1))

In Exercises 30 through 33, solve the equations for x (compare outputs using both the Solve and NSolve commands):

30. (x^2)-x+1=0		31. ((x(1-2x))^(-3/2))+(((1-2x))^(-1/2))=0		32. (x^3)-1=0		33. (Sqrt[1+(Sqrt[x+(Sqrt[(x^2)])])])=5