MATH 021- Z1 Tutorial (Part 1)

Getting Started: Examples

By Helen P. Read, University of Vermont. Last revised January 2013.

Click on the box above and type in your name.

Remember to save your file periodically while you work so that if something goes wrong you don't lose everything.

Getting Started

Before you begin, open up the Classroom Assistant palette if it is not already open. (Look for it under Palettes on the Mathematica menu at the top of the screen.) In the Classroom Assistant palette, open up the Calculator (Advanced view).

Try some simple arithmetic

Click on the following input cell, which contains an example of an arithmetic calculation, and evaluate it by typing Shift-Enter, or click the Enter button in the Classroom Assistant palette. You should get the result of the calculation (called the output) immediately below the input.

((10(5-(2^3)))/6)

Try your own example.

First, make a new input cell by clicking the Create Input Cell button on the palette. Then try typing in a simple example. You can find buttons for fractions, square roots, exponents, etc. on the Calculator in the Classroom Assistant palette. Evaluate your expression with Shift-Enter from the keyboard, or click the Enter button on the palette.

Try a trigonometric function.

Make a new input cell below this text cell, and find the value of tan((π/3)). Click on the Cos button on the palette, and fill in (π/3), then evaluate it.

Decimal Numbers: The N[ ] Command and Significant Digits

To find a decimal approximation of a number, use the command N[expr,digits]
where expr is the expression you wish to approximate, and digits is the number of significant digits that you want to calculate.

For example, to calculate (Sqrt[3]) to 4 significant digits, evaluate the following.

N[(Sqrt[3]),4]

If you do not specify the number of significant digits, the result will usually be given to 6 significant digits.

N[(Sqrt[3])]

For practice, use N to find a decimal approximation of π to 3 significant digits (so you should get 3.14).

Then use N to find a decimal approximation of π to 1000 significant digits.

Algebra

On the Basic Commands portion of the Classroom Assistant palette, select the second tab, where you will find some common algebra commands. Grab the command that you need from the palette and fill in the expression, using the Calculator portion of the palette to make fractions, exponents, etc. Use the Tab key to advance from one field to the next as you fill everything in.

Practice

(See below to check your answers.)

(a) Simplify the expression (((x^2)-16)/(3x-12))

(b) Factor the expression 221(x^2)+59x-10

(c) Multiply out (expand) the expression (((2x-5))^4)

(d) Solve the equation ln((x^3))=2 for x. Give both the exact answer and a decimal approximation to 8 significant digits.

Answers

(a) ((4+x)/3)

(b) (13 x+5) (17 x-2)

(c) 625-1000 x+600 (x^2)-160 (x^3)+16 (x^4)

(d) x=(e^(2/3)) (exact)
     x≈1.9477340410546758575`8. to 8 significant digits

Assigning Names

When working in Mathematica, it’s a good idea to name things that you are going to use again. To do this, simply type a name at the beginning of the line, followed by an equal sign.

As an example, let’s find the exact value of cos((π/12)) as well as a decimal approximation to 8 significant digits. First, we find the exact value and name it.

b=Cos[(π/12)]

Now we can apply N to find a decimal value for the expression that we named b.

N[b,8]

Answer: The exact value of cos((π/12))=((1+(Sqrt[3]))/(2 (Sqrt[2]))). This is approximately 0.96592583 (to 8 significant digits).

If you want to reuse the same name for something else, you can clear it like this.

Clear[b]

Practice

Find the exact value of (Sqrt[cot((π/12))]) and name it something. Then find a decimal approximation of the answer to 8 significant digits. See below to check your answer.

Answer

(Sqrt[cot((π/12))])=(Sqrt[2+(Sqrt[3])])  (exact answer)

(Sqrt[cot((π/12))])≈1.93185165257813657349948639945779473527`8. (decimal approximation to 8 significant digits)

Defining Functions

Example Define a function  f(x)=3+4x sin((x/3)) and evaluate f(0) and f(π).

To begin, start a new input cell and pick Define Function from the palette. (It's on the Calculator portion of the palette, in the Advanced view.)

Fill in f for the name of the function, x for the variable, and 3+4x Sin[(x/3)] for the expression. The whole thing should look like this f[x_]:=3+4x Sin[(x/3)]

Make sure you type a space between x and Sin[(x/3)]. Don’t run “xSin” all together in one word.

Once it is all okay, go ahead and evaluate. You won’t get any output when you evaluate it, but you will get an In number.

Substitute a value into your function

To subsitute a value into your function, just plug in the value, with square brackets around whatever the function is "of". For example, to find f(0), just type in f[0] in a new input cell, and evaluate it. Go ahead and try it. (What should the answer be?)

Now find f(π). Find the exact value, and also a decimal approximation to 10 significant digits. Copy and paste your answers into the AnswerBox provided.

Answers

f(0)=3
f(π)=3+2 (Sqrt[3]) π≈13.88279619

The Plot Command

Example Plot f(x)=sinx and g(x)=cosx for x from 0 to 4π.

Before you begin, make a new input cell, put in Clear[f] and evaluate. (This clears the definitions of f[x] from the previous example.) There is a button for Clear on the palette, or just type it in yourself.

After you have cleared f, define functions for f(x)=sinx and g(x)=cosx

Now look on the 2D tab on the Basic Commands area of the palette, pick Plot, and fill in f[x] for the function, x for the variable, and 0 and 4π for the min and max values of x. When it’s all filled in, go ahead and evaluate.

Do the same thing to make a plot of g(x).

Plot both functions together on the same plot.

Look on the palette under More (next to Plot) and select the first item, which is a template for plotting more than one function at a time. Use this to plot f(x) and g(x) together.

Practice

Define functions u(x)=(x^2),  v(x)=(x^2)-4, and w(x)=(x^2)+4 and plot them all together, for x from -5 to 5.

The Table Command

If you need to evaluate a function at several different x-values, make a table.

Example Evaluate f(x)=2(x^3)-9(x^2)+4x+2 for x=1, 2, 3, ... , 15

Clear[f] before you begin. Then define a function for f(x).

After you define your function, find the values of f(1), f(2), and  f(3). Remember to use square brackets around the values you are plugging into the function. See below to check your answers.

Answers

f(1)=-1
f(2)=-10
f(3)=-13

Make a Table of values of f[x]

Now, let's find f(1), f(2), f(3), ...,  f(15) by making a table. To do this, make a new input cell, and pick Table from the palette (you can find it on the Calculator, Advanced view). Fill in f[x] for the expression, x for the variable, 1 for the starting value, and 15 for the ending value, and then evaluate it. Check that the first few values in your table agree with what you got previously for f(1), f(2), and f(3).

Make sure you have the table working before you go on to the next step.

Make a Table of Ordered Pairs {x,f[x]}

Instead of listing just the y-values f(1), f(2) etc., it’s better to list ordered pairs (1,f(1)), (2,f(2)) etc., so that we can see which x goes with which y-value. To do this, use {x,f[x]} in place of f[x] for the expression in the table. Note the curly braces { } around the ordered pair. Go ahead and try it for our example. Make sure it’s working before you go on to the next step.

Make it look nice

Once you have your table of ordered pairs working, wrap Grid[] around the entire Table[] so that it looks like the following. There's no button for Grid, so just type that part in yourself.

Grid[Table[{x,f[x]},{x,1,15}]]

Finally, add a frame. In the input cell where you made your Grid, put the cursor inside the last bracket. Type in a comma, then Frame->All (you can get the arrow from the palette). Now when you evaluate your Grid you should now have a nice frame around everything.

Answers

Your final Grid should look like this.

({{1, -1}, {2, -10}, {3, -13}, {4, 2}, {5, 47}, {6, 134}, {7, 275}, {8, 482}, {9, 767}, {10, 1142}, {11, 1619}, {12, 2210}, {13, 2927}, {14, 3782}, {15, 4787}})

Increments

One last example: Let’s find f[x] for x from 1 to 2 in increments of (1/4). The increment goes after the starting and ending values, like this.

Grid[Table[{x,f[x]},{x,1,2,(1/4)}],Frame->All]

For practice, modify this last table so that the y-values are displayed as decimal numbers to 3 significant digits (leave the x-values as fractions).

What happens if you use 0.25 for the increment instead of (1/4)? Can you still display the x-values as exact fractions and the y-values rounded to 3 significant digits?

Clear Everything Before You Continue on to Part II of the Lab

Before you continue on to Part II of the lab, clear everything by evaluating the following command. (This is a global clear, which clears all of the names and functions you have defined up to this point.)

Clear["`*"]