Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf ·...

8
Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who have never used Mathematica before and especially for those who have little to no experience with programing in general. If you have some expereince you may wish to skip to some of the later tutorials on Calculations and Complex numbers. These tutorials can be found on the course website for Math 421 under group 1. Tool Bar File This tab on your tool bar is just like what you’ld see on a word document. You have Save, New, Open and so on. Format This tab on your tool bar will allow you to play with the font, or the style of the document you have open, if plain black and white is too boreing for you. Try out different Stylesheets for fun. Palettes In this tab you will find many useful things. Most useful of all is the Basic Math Assistant for those just starting out. This will allow you just to click and input equations, integrals, matrices and so much more! Help Here you will find lots of helpful things if you should be lost. Most helpful of all will be the Documentation Center. The Documentation center is a library of useful commands and example programs. It will also give basic explanations and definitions of what it is you are looking up. Text/document Notebooks This document you happen to be browsing now is an example of a Notebook. It’s a great place to work out problems and to save thoughts and notes on work your doing. It allows you to keep track of your progress as well as being an incredible tool for finding solutions. Cells If you look to the side you may notice these odd little brackets that seem to delineate different lines. Some are even nested. These are what we call cells. They can come in a few different styles though the two most common are input and text. This one here is an example of a text cell. Printed by Mathematica for Students

Transcript of Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf ·...

Page 1: Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf · Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who

Getting started in Mathematicaby Sarah Zuraw

This tutorial is designed for those who have never used Mathematica before and especially for those who havelittle to no experience with programing in general. If you have some expereince you may wish to skip to some ofthe later tutorials on Calculations and Complex numbers. These tutorials can be found on the course website forMath 421 under group 1.

Tool Bar

� File

This tab on your tool bar is just like what you’ld see on a word document. You have Save, New, Open and so on.

� Format

This tab on your tool bar will allow you to play with the font, or the style of the document you have open, if plainblack and white is too boreing for you. Try out different Stylesheets for fun.

� Palettes

In this tab you will find many useful things. Most useful of all is the Basic Math Assistant for those just startingout. This will allow you just to click and input equations, integrals, matrices and so much more!

� Help

Here you will find lots of helpful things if you should be lost. Most helpful of all will be the DocumentationCenter. The Documentation center is a library of useful commands and example programs. It will also give basicexplanations and definitions of what it is you are looking up.

Text/document

� Notebooks

This document you happen to be browsing now is an example of a Notebook. It’s a great place to work outproblems and to save thoughts and notes on work your doing. It allows you to keep track of your progress as wellas being an incredible tool for finding solutions.

� Cells

If you look to the side you may notice these odd little brackets that seem to delineate different lines. Some areeven nested. These are what we call cells. They can come in a few different styles though the two most commonare input and text. This one here is an example of a text cell.

Printed by Mathematica for Students

Page 2: Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf · Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who

This line is not, and as you can see most of the words are blue. Mathematica is looking at if as

if it were some sort of command. If however I tried to run this command Mathematica would

freakout and rightly so as this is not in any format that mathematica would understand.

� Style sheets

Style sheets are a purely atheistic thing. The one I’m using now is just the default. But if you like to work innatural colors or pastels that is an option that you should feel free to explore. Just go the format tab, go to stylesheets and the click stylesheet chooser to see all the options you have.

Easy way to start

� Free Form linguistics input

If you don’t have any experience with Mathematica that is okay! Mathematica is smart enough to understand youeven if you don’t understand it. If you have accuse to the Internet you can use Mathematica as if it were Wolfram-alpha or Google.

� The “=” sign

In order to do this you have to use the “=” sign. You know you have it right when it looks like this

To enter it all you have to do is access and new cell. (You can press the down arrow on your keyboard to do thisquickly) Then just press the equal’s sign. Once there enter what you’re interested in after the equals sign. Let’ssay I’m interested in tacos let’s go ahead and look that up.

tacos

Now I just press enter after the word “tacos” and here’s what I find.

2 Tutorial for class.nb

Printed by Mathematica for Students

Page 3: Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf · Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who

serving size 1 taco H140 gL

total calories 304 fat calories 148

% daily value*

total fat 17 g 26%

saturated fat 9 g 47%

trans fat

cholesterol 46 mg 15%

sodium 657 mg 27%

total carbohydrates 22 g 7%

dietary fiber

sugar

protein 17 g 34%

vitamin A 14% vitamin C 3%

calcium 18% iron 11%

thiamin 8% riboflavin 21%

niacin 13% vitamin B6 10%

vitamin B12 14% folate 14%

phosphorus 17% magnesium 14%

zinc 21%

*percent daily values are based on a 2000 calorie diet

Neat! But what about something more useful and related to math? Let’s try graphing sin(x). You may not knowhow to ask Mathematica to do that directly but we can simply look it up using “=” and see if Mathematicaunderstands what we want.

graph sinx

Plots (1 of 2)

Plot@Sin@xD, 8x, -6.6, 6.6<D

-6 -4 -2 2 4 6

-1.0

-0.5

0.5

1.0

Great! I’ve got my graph of sin(x) I wanted. But that’s not all. If you look at the line with the “=” you will see agray + sign in the top right corner. Let’s go ahead and click on it and see what happens

Tutorial for class.nb 3

Printed by Mathematica for Students

Page 4: Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf · Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who

Great! I’ve got my graph of sin(x) I wanted. But that’s not all. If you look at the line with the “=” you will see agray + sign in the top right corner. Let’s go ahead and click on it and see what happens

4 Tutorial for class.nb

Printed by Mathematica for Students

Page 5: Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf · Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who

graph sinx

Plots (1 of 2)

Plot@Sin@xD, 8x, -6.6, 6.6<D

Input interpretation:

plot sinHxL

Plots:

Plot@Sin@xD, 8x, -6.6, 6.6<D

-2 Π -Π Π 2 Π

x

-1.0

-0.5

0.5

1.0

min max

Plot@Sin@xD, 8x, -26, 26<D

-20 -10 10 20

x

-1.0

-0.5

0.5

1.0

min max

Tutorial for class.nb 5

Printed by Mathematica for Students

Page 6: Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf · Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who

-6 -4 -2 2 4 6

-1.0

-0.5

0.5

1.0

It has given me a whole bunch more information that it thinks I may have wanted or would be interested in.Which is always helpful. If you’re being vauge about waht you’re asking mathematica try clicking the gray “+“and even if what you wanted was not the first thing Mathematica showed you it might be included in theexpanded version.

� Mathematica’s Programing Language

Now that you know how to use Mathematica as a search engine we can get down to using Mathematica as thepowerful program that it is! Not just a glorified google search bar. Bellow you will find the four basic rules toremember about the Mathematica programing language.

� Four basic rules about language1. Capital Letters on all function names2. Use square brackets for anything you want to calculate3. Use curly braces for any lists or ranges4. Shift+enter to run calculations

These four things will get you pretty far in Mathematica and in the next part of the tutorial you will find out moreabout programing, plotting and graphics. Before I leave you though I just want to give you a few more helpfulhints that will aid the non-programers in the crowd.

� Grab command lines from your search

If you’ve searched something like say the graph of sin(x) you may have noticed that above your plot is this linethat looks something like this

Plot@Sin@xD, 8x, -6.6, 6.6<D

This is an example of a Plot command in the Mathemtica programing language. Right now it is perfectly set up toproduce a plot of sin(x) from -6 to 6. You didn’t need to know anything about the programing language to set itup you just had to copy paste. This trick can be very useful with more difficult functions.

Let’s go ahead and try this command out. First press the down arrow key to open a new cell. This cell should bean input cell not a text cell.

6 Tutorial for class.nb

Printed by Mathematica for Students

Page 7: Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf · Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who

If you’ve searched something like say the graph of sin(x) you may have noticed that above your plot is this linethat looks something like this

Plot@Sin@xD, 8x, -6.6, 6.6<D

This is an example of a Plot command in the Mathemtica programing language. Right now it is perfectly set up toproduce a plot of sin(x) from -6 to 6. You didn’t need to know anything about the programing language to set itup you just had to copy paste. This trick can be very useful with more difficult functions.

Let’s go ahead and try this command out. First press the down arrow key to open a new cell. This cell should bean input cell not a text cell.

Plot@Sin@xD, 8x, -6.6, 6.6<D

You will notice that in this version the x is colored blue. That’s Mathematicas way of denoting that x is a vari-able. It is also one way to tell if the cell you are working with is indeed an input cell and not a text cell.

Next while you still having your curser on the same line as your command press shift+enter to exicute yourcommand.

Plot@Sin@xD, 8x, -6.6, 6.6<D

-6 -4 -2 2 4 6

-1.0

-0.5

0.5

1.0

Wonderful, you’ve just exicuted your first Mathematica command. The advantage to this is that all the computa-tions for this plot were done internally on your computer. You did not call the server to create this plot and thatmeans you don’t need the internet to make such plots.

� Final Notes and tips

Most everything in Mathematica is interactive so if you wish to change something about your plot go right ahead.You can change the axis or function just by going in to a previous line and changing things around. Then justclick shift+enter at the end of the line and your plot will change to what every you told it to do.Also if you go to the Documentation Center and search some topic of interest, you will often find examples.These examples can also be manipulated right in the Documentation Center window (and also reset if you shouldneed to do so).

I hope this has been helpful and please take a look at some of the other tutorials my team

mates have made on

Calculations and GraphingAnd

Complex Numbers

Tutorial for class.nb 7

Printed by Mathematica for Students

Page 8: Getting started in Mathematicapeople.math.umass.edu/~turk/courses/mathematica-tutorial.pdf · Getting started in Mathematica by Sarah Zuraw This tutorial is designed for those who

I hope this has been helpful and please take a look at some of the other tutorials my team

mates have made on

Calculations and GraphingAnd

Complex Numbers

8 Tutorial for class.nb

Printed by Mathematica for Students