Math 161 Lab: Functions, Graphs, and Equations in Mathematica  



In this lab you will be introduced to some of the numerical and algebraic things Mathematica can do. You will also be reviewing how to work with Mathematica expressions, and how to define and plot functions. Work in groups of two at one computer and turn in one set of solutions to the exercises for your group (with both names on it).

Remember, you can select all the things you want to print by clicking on the bars at the right side of the notebook. Hold down the apple key while you do this to add each new item to your selection. Then when you choose ``Print Selection'' from the ``File'' menu, only what you have selected will print.

1  Some Review

E
nter Sin[Pi], N[Sin[Pi]], and Sin[N[Pi]]. Record the results and explain the differences you see.
W
hich is larger: ep or pe? About how much larger?

2  Options to Plot

If you type ??Plot (try it now), you will see a list of options to the plot command. These options allow you to control various aspects of your graphs like colors, line thickness, etc. We will learn about two useful options. AspectRatio->Automatic will make the two axes use the same scale. This is important if you want to see circles as circles (rather than ellipses) or to ßee" the slope of a line without having to adjust for the scales.

Compare the results of the following two commands:

You will get some error messages when you do the example above. Why do you get error messages and what can you do to eliminate them?

You can set the color of the graph, use PlotStyle -> Hue[]. For example, Plot[Sqrt[4 - x^ 2] , {x, -3, 3}, PlotStyle->Hue[.5]] or Plot[Sqrt[4 - x^ 2] , {x, -3, 3}, PlotStyle->Hue[1 1 0]] . See ??Hue for more information.

3  Plotting Multiple Functions

Often you want to see more than one function on the same coordinate system. Plot is capable of doing that. Type ?Plot and see if you can figure out how to do it. (You might want to click on the word "More" to get additional help and examples if you can't figure it out from the first results you get from ?Plot.

Plot three functions on a single coordinate system: f(x) = sin(x), a graph that is shifted left 2 units, and a graph that is compressed by a factor of 3 horizontally and stretched by a factor of 2 vertically (it will wobble 3 times as fast and 2 times as high). Print out both the graph and the command you used to generate it (but not the rest of your notebook). You might like to make them different colors, but this is not required. This is the only thing you must print.

Plotting multiple functions makes use of an important Mathematica structure: a list. Lists in Mathematica are surrounded by curly braces. May Mathematica functions like Plot[] can handle lists of inputs as well as single inputs. For example, to get the value of a function at several points, one can type something like f[{1,2,3,4,5}]. Define a function and give it a try to see what the output looks like. You could also use this to compare two values: {Sin[1],Sin[2]}.

4  Algebra and Solving Equations

Mathematica has several methods of manipulating expressions algebraically and ßolving" equations. We will learn about some of these today. Enter the following and see what they do:

Based on the results above, write a brief description of what each of these five functions does.

Find the factors of 123456789 and 987654321. (You may need to read some of the help information or experiment a little bit to figure out how to interpret the results you get.)

Solve [] and NSolve[] can be used to sove equations. Solve[] attempts to find exact solutions by algebraic means (by factoring, rearranging, etc), and NSolve[] attempts to find numerical solutions. Type Solve[ x^ 2 -x -1 == 0, x]. Notice that Mathematica uses to represent an equals sign in equations. The last x tells Mathematica what variable to solve for.

Mathematicacan even solve equations involving trig functions:

U
se Mathematica to solve sin(x) = cos(2x).
Mathematica
 will warn you that it may not have found all solutions. Find at least one solution Mathematica missed, or explain how you know they have all been found.
Now try solving sin(x) = 5 cos(x). This time the answer is expressed in terms of the functions arccos(x). We will learn about that function later this semester. For now, try using NSolve[] in place of Solve[]. NSolve[] gives its results as decimal approximations.

Use Solve[] and NSolve[] to find all the roots of the function g(x) = [(x7 -6x5 + 11x3 - 6x)/(1+x2)] Give exact values for as many as you can. Give decimal approximations for all solutions.

G
ive numerical approximations to the solutions of sin(x) = 5 cos(x).
Mathematica
again warns that some solutions may not be included in its list. Find a missing solution or explain why no more solutions exist.
Find all real solutions to x7 - x6 - x5 - 4x3 +3x2 + 5x + 1. Give exact values for as many as you can. Give decimal approximations for all solutions.


File translated from TEX by TTH, version 2.78.
On 14 Sep 2001, 11:15.