SCCC Mathematica Tutorial, © 2007-2020, Seattle Central Community College Math Dept., contact: Greg.Langkamp@seattlecolleges.eduVersion 1.9/ March 2020
Important!
Click "Make your own Copy" in the black ribbon above to make this document interactive. You will also need to be logged into Wolfram Cloud
Click "Make your own Copy" in the black ribbon above to make this document interactive. You will also need to be logged into Wolfram Cloud
The Six Most Important Rules of Mathematica Syntax
The Six Most Important Rules of Mathematica Syntax
At this point in the tutorial we pause to review six important rules of Mathematica syntax. Some of these rules take a little getting used to. However one of the great strengths of the Mathematica language is that it is completely consistent. Once you master these six rules, you can use them in any situation and know that they will work.
Rule 1. Parentheses ( ) are used for order of operations (algebraic grouping) purposes only.
Parentheses are used in the usual way to group subparts of an algebraic expression. Never use square brackets [ ] or curly braces { } in algebraic expressions. Mathematica is very consistent. The only place that you will ever use parentheses in Mathematica is for grouping in algebraic expressions.
Rule 2. Mathematica commands and functions always start with a capital letter.
Every built-in Mathematica command, such as Factor begins with a capital letter. Likewise every built-in mathematical function, such as Sin, begins with a capital letter. If you define your own function, you do not have to capitalize the first letter. In fact it is recommended that you use lower case names for your functions so that you can distinguish them from the functions that are built into Mathematica. [see Rule 4 for syntax used to enter your own functions].
Rule 3. Square brackets [ ] are used to enclose the inputs to commands and functions only.
When entering a command or a function we always use square brackets to enclose the inputs. For example, to factor the expression -4 we enter . Likewise for functions, we use Sin[π] to evaluate . This is the only place where square brackets are used in Mathematica . They are not used in algebraic expressions. So for example we do not enter ,but instead, we use parentheses throughout: 5((x+3)+8) .
2
x
Factor[x^2-4]
sin(π)
5[(x+3)+8]
Rule 4. To define a function in Mathematica use the form
f[x_]:=x^2
To define the function we enter . Note there are three things to remember here:(1) We must use square brackets to enclose the function input, (2) We attach an underscore to the variable, "x_" on the left hand side (but not on the right), and(3) We use colon equals := .Note that the "x_" is only used when we initially define the function. After that, represents the function evaluated at .
f(x)=
2
x
f[x_]:=x^2
f[x]
x
Rule 5. Curly braces { } are used for lists only.
Whenever you need to enter a list in Mathematica, whether it's a list of numbers, or functions to graph or whatever, you always use curly braces . So for example, the list of the numbers 2, 4, and 6 is entered in Mathematica as . Mathematica is very consistent. The only place that you will ever use curly braces in Mathematica is to enter a list.
{}
{2,4,6}
Rule 6. Equations are entered using double equal sign ==.
To enter an equation in Mathematica we must use a double equal sign. So to enter an equation such as in Mathematica we enter .
5x-8=7
5x-87