I teach a physical sciences class in which I use Mathematica as a vehicle for instruction.
For the first week or so, I teach Mathematica basics.
I've been compiling a list of typical beginner mistakes and "gotchas". In addition to the working examples in the documentation, I find it useful to illustrate typical mistakes as well.
Here is a list of typical beginner mistakes. Can anyone add to it? (Again, this is for students who are at the beginning of the learning curve for Mathematica). These aren't necessarily mistakes, but examples of doing something with unintended consequences.
()-parentheses for function calls:
Cos (kx)
upper case/lower case
arccos[Pi]
List indexing
someList = {1, 2, 3, "a"};
someList[1]
Operator precedence
( -b + Sqrt[b^2 - 4 a c])/2 a
No patterns in a function definition
myFunction[x, y, z] := Sin[x] Sin[y] Sin[z]
myFunction[1, 2, 3]
Prior definition and no set delayed in function definiition
x = Pi/2;
absSin[x_] = Abs[Sin[x]]
Plotting things that don't evaluate to numbers
x = Pi/2;
absSin[x_] = Abs[Sin[x]]
Plot[absSin[z], {z, -Pi, Pi}]
*Not using == in Solve**
Solve[{p = 2 q + r a, q = a - p - q^2}, {p, q}]
Evaluate in functions with Hold attributes
Plot[Table[Sin[ k x], {x, 0, 2 Pi}], {k, 1, 4}]
Typeset forms are not what they appear to be
matrix = {{1, 4}, {4, -2}} // MatrixForm
Eigenvalues[matrix]
Small imaginary parts appear as a result of numerical evaluation
sinExp[x_] := (Exp[Sqrt[-1] x] - Exp[-Sqrt[-1] x])/(2 Sqrt[-1])
Table[sinExp[x], {x, -Pi, Pi, .1}]
===============================
Not recognizing when there is Nonstandard Argument Evaluation
myExpression = ( -b + Sqrt[b^2 - 4 a c])/(2 a)
Manipulate[
myExpression,
{a, -1, 1},
{b, -1, 1},
{c, -1, 1}
]
(note: here is how one might go about fixing the above "error")
With[{myManipulateExpression = myExpression},
Manipulate[myManipulateExpression, {a, -1, 1}, {b, -1, 1}, {c, -1, 1}]
]
===============================
Integer arguments to Part in Manipulate
randomWalk = Accumulate[RandomReal[{-1, 1}, {1024}]];
Manipulate[ListPlot[randomWalk[[1 ;; step]]], {step, 1, 1024}]
Mathematica is chronological and not spatial: the value of something depends on when it was defined and not where (within a notebook) it appears.
with thanks to David Reiss: Notebooks that share the same kernel (and have the same context). In other words, notebooks typically share definitions of symbols