Mathematica Tutorial. Defining constants, functions and plotting:

Mathematica Tutorial Mathematica is a great program to do complicated calculations, create graphics, and write technical documents. Mathematica consis...
Author: Evelyn Sparks
3 downloads 0 Views 2MB Size
Mathematica Tutorial Mathematica is a great program to do complicated calculations, create graphics, and write technical documents. Mathematica consists of "cells" that are indicated on the right side of the document. Each cell has a defined format that can be chosen by clicking on the "Format" tab and going to "Style". This brings up a menu of all the styles that can be defined in a cell. For example the cell this text exists in, is the "Text" style. The default style is the "Input" style. The styles you will use most are as follows: Title, Subtitle Section, Subsection, Input, Output. First title your Mathematica document as "Mathematica Tutorial" by clicking the Format tab and choosing "Title" from the Style menu. Then, with your mouse place the cursor below your title until the cursor becomes horizontal and click there. This creates a new cell. Go to the Format tab and choose "Subtitle" from the style menu and type "Defining constants, functions and plotting:".

Defining constants, functions and plotting: Click below your Subtitle (when the cursor is horizontal) and type the following that appears in bold (Don't worry about choosing a style, the default is Input). After you have typed in the first seven lines below press “Shift+Return”to evaluate and you should see the results of A + B, A - B, etc... A = 3; B = 4; A+B A-B AB A*B AB 7 -1 12 12 3 4

A is defined to be 3, B is defined to be 4. The semicolon's at the end of the A and B definitions tells Mathematica not to show the output evaluation. The third line in the first input A+B is evaluated to be 7 which is shown in the output evaluation. To subtract two objects just use the - (minus) sign. Multiplication can be typed as a space or * between the objects to be multiplied and divide is represented by / . In order to evaluate an equation, function, or graph you must press "Shift+Return" or “Enter”on the number pad and Mathematica will evaluate everything in that cell and display the output below everything you have typed. Another option is to go to the "Evaluation" tab and click on "Evaluate Cells" or "Evaluate Notebook". Now we will define a function and plot that function on a graph. We define a function f[x_] = Bx^2 + A*100/(x+1). The f[x_] is a pattern in which x_ stands for any expression (which is represented on the right-hand side by the name x). The rule says: if you have f of any expression, replace it by the defined 9/18/13 expression as seen above. So f[3] = B*3^2 + A*100/(3+1).

In order to evaluate an equation, function, or graph you must press "Shift+Return" or “Enter”on the number pad and Mathematica will evaluate everything in that cell and display the output below everything you have typed. Another option is to go to the "Evaluation" tab and click on "Evaluate Cells" or Scott Pinegar Mathematica Primer.nb | 2 "Evaluate Notebook". Now we will define a function and plot that function on a graph. We define a function f[x_] = Bx^2 + A*100/(x+1). The f[x_] is a pattern in which x_ stands for any expression (which is represented on the right-hand side by the name x). The rule says: if you have f of any expression, replace it by the defined expression as seen above. So f[3] = B*3^2 + A*100/(3+1). f@x_D = x + HB x ^ 2L + HHA 100L  Hx + 1LL Plot@f@xD, 8x, 0, 10