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.
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.
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]}.
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:
Notes:
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:
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.