Math with Mathematica, Fall 2018
Tutorial 1
This page is for a past course. Find your current course here.
 

Once you have access to an installation of Mathematica, you need to know how to use it.

Opening the Program

  • If you are on a Windows machine in an on-campus computer lab, go to Start Menu, then Programs, then Wolfram Mathematica. Click on the icon for Mathematica, named Spikey.
  • If you are on a Mac computer, use the Finder magnifying glass in the upper right corner to search for Mathematica.
  • Up will pop an introductory window. On the left hand side of this button is an option to create a new Mathematica notebook or open an old one. The notebook is where all your interactions with the program will take place.

First steps with Mathematica

  • Download this file and save it to your computer: 213fa18tut1.nb (Use Right-Click > Save As...)
  • Open the file. The file should look like a "Powerpoint" Presentation. If it does not, go to the Format Menu and click on "Format > Screen Environment > SlideShow".
  • Follow this tutorial step-by-step and discuss the most interesting aspects with your neighbors.
  • At the end of the tutorial, use additional class time to explore the power of Mathematica. For your second homework assignment, you will be compiling two cool things that Mathematica can do. I suggest looking in the Documentation Center (in the Help Menu) or at the Wolfram Demonstrations Project. Feel free to explore on your own or with your neighbors.
    If you are having trouble getting started, here is what I do when I am exploring:
    • I go to the Documentation Center and type in a command (such as Manipulate)
    • I do a quick look at the selected examples that are given and see if they are interesting.
    • If so, I want to see all the examples. So I select the entire notebook (Ctrl-A or Apple-A) and then open all subgroups (Cell Menu: "Grouping > Open All Subgroups").
    • I play around with the examples, moving sliders, changing variables to see what happens.
    • If I see a command I do not know, I will search for it in the Documentation Center
    • At the bottom of the file is a "See Also" section, which tells you similar commands.
    • Also at the bottom are links to more in depth tutorials, which can be useful sometimes.

Helpful Mathematica techniques

  • Keep a diary! Write down commands that you have explored, keeping track of syntax, interesting things that you can do, and questions that pop up.
  • Think before you code! Before you start typing, think about what you want the computer to do, and how you would be able to write a logical sequence of commands to do this thing. Write some pseudocode out first.
  • Build in stages! When trying to get Mathematica to do a multi-step command, make sure each nested command works before trying to wrap it in another command. Work from the inside of the onion outward!
  • Copy, modify, repeat! When you have code that is working, don't modify it. Copy it to the next line and then modify it. This forms a page of scratch work.

Other Items of Note!

Many of your initial errors will come about because of one of the following two problems:
  • Mathematica is Case-SenSitive (AA is not the same as aA), so be careful about what you type.
    In particular, all built-in Mathematica functions are spelled out and capitalized, such as Table, ListPlot, IntegerPart, etc.
  • In Mathematica, it is important to distinguish between parentheses (), brackets [], and braces {}:
    • Parentheses (): Used to group mathematical expressions, such as (3+4)/(5+7).
    • Brackets []: Used when calling functions, such as N[Pi].
    • Braces {}: Used when making lists, such as {i,1,20}.
    If you use the wrong symbols in the wrong places or if you do not have a closing symbol for every opening symbol, Mathematica will give you an error message.
  • In Mathematica, there are four types of equals: =, ==, :=, and ===. We will learn the difference between all of them; at the beginning of this semester, you only need the first two.
    • To define a variable to store it in memory, use =. For example, to define z to be 3, write z=3.
    • You use == to check for equality. For example, 1-1==0 will evaluate to True and 1==0 will evaluate to False.
    • You use := to define your own command. (This is advanced.)
    • You will likely not use === in this class.
  • One of the most important things to do is explore. If you are having trouble with a certain function, use the ? command to ask for help. Enter ? Table and the output will be a yellow box with a quick synopsis of the command. For more detailed information, click the blue >> at the bottom right of this yellow box. This will open the Documentation Center which gives examples of using the command in action, available options for this command, and anything else you might want to know about the command.

Algebra and Calculus

Mathematica will do everything your calculator can and more.
  • Use ^ to put something to a power.
  • pi is Pi, e is E and sqrt(-1) is I.
  • If you want to see the numerical approximation to a fraction or irrational number, use the function N. For example, to find the decimal represenation of pi, write N[Pi].
  • Use E^x or Exp[x] to represent the function ex.
  • To take the derivative of a function, use D and specify the derivative with respect to which variable. For instance D[x^2 + 3x, x].
  • To take the integral of a function, use Integrate and specify the integral with respect to which variable. For instance Integrate[x^2 + 3x, x].
  • To solve for the roots of ax2+bx+c=0 symbolically, use Solve[a x^2 + b x + c == 0, x].
    Notice the double equals sign. (Mathematica is searching for when the expression is True.)
  • Coefficient[(1 + x)^10, x^3] gives the coefficient of x3 in the expansion of (1 + x)10.