Common Mistakes for Beginners to Mathematica

Part ONE

Forgetting or not understanding the differences between (⋯) {⋯} [⋯]

(⋯)  parenthesis are for logical grouping and are useful when you are unsure which operations take precedence

Three Examples of common mistakes:

Cos(k x)

Plot[Sin[x],(x,0, π)]

Sort[(x,y,z)]

{⋯}  curlies are for lists, iterators, and variable bounds

Example of a common mistake:

{((Sqrt[2])/2)}{a,b,c}

[⋯]  single brackets are for lists, iterators, and variable bounds
		Common Mistakes:

Examples of common mistakes:

SomeList = {a,b,c,d};

SomeList[1]

[((z^2) + (y^2))c + b (y^3)]a

[[⋯]]  double brackets are for lists, iterators, and variable bounds

Example of common mistake:

Exp[[1]]

Forgetting Mathematica's convention of capitalization of Functions

Examples of common mistakes:

arccos[1]

Arccos[1]

Forgetting to use patterns in function definitions

Examples of common mistakes:

MyFunction[x,y,z] := Sin[x] Sin[y] Sin[z]

MyFunction[π,π/2,0]

Forgetting to delayed evaluation, :=, in function definitions when the placeholders have been previously defined.

Example of common mistake:

x= π/2;
AbsSin[x_] = Abs[Sin[Abs[x]]]

Plot[AbsSin[z],{z,-2π,2π},PlotStyle->Thick]

Part TWO

The difference between assignment = and equality testing ==

Examples of common mistakes:

Solve[{h= 3 p + 4 q, k = 5p - q},{p,q}]

δ == 24

Not using enough commas

Example of a common mistake:

Plot[Sin[x + Exp[-x]] {x,0,Pi}]

7. Forgetting that a variable has been defined

Example of common mistake:

A = (E^((-1.2)/(k 373)))

Practical Advice 1:
		Clear Variables

Clear[k];
A = (E^((-1.2)/(k 373)))

Practical Advice 2:
		Second to last resort, clear everything

Clear["Global`*"];

Practical Advice 3:
	Last resort, kill the kernel and restart it  Use menu: Evaluation

Part THREE

Using a function from a package, before loading the package

Histogram3D[Table[{RandomReal[],RandomReal[]},{5}]]

To load the package ...

<<Histogram`

find the correct name (The package directories are located in "Packages" in "AddOns" the $InstallationDirectory, on macintosh:

SetDirectory[$InstallationDirectory]

FileNames[]

SetDirectory["AddOns"]
FileNames[]

SetDirectory["Packages"]
FileNames[]

Doing this correctly now ...

<<Histograms`

Histogram3D[Table[{RandomReal[],RandomReal[]},{20}]]

Using formatting commands in assignments

Examples of common mistakes:

mymat = {
                 {1,3,7},
                 {3,2,4},
                {7, 4 , 3}
               }//MatrixForm

Eigenvalues[mymat]

Practical advice, define and display with separate commands

mymat = {
                {1,3,7},
                 {3,2,4},
                {7, 4 , 3}
               };
mymat//MatrixForm

Eigenvalues[mymat]//N

Older versions of Mathematica (previous to 6.0) required that the functions begin plotted had to be evaluated first.  If you use older notebooks, you will see this. Post 6.0, using evaluate still works but affects the behavior, notive the time to compute and the appearance of the following two plots. As you will see below, using Evaluate still improves the behavior...

Not using Evaluate : slow and monochrome.

Plot[Table[LegendreP[i,z],{i,1,11,2}],{z,-1,1},PlotStyle->Thickness[0.01]]

Using Evaluate : Fast and multicolored.

Practical advice:
			Use Evaluate in Plot when in doubt

Plot[Evaluate[Table[LegendreP[i,z],{i,1,11,2}]],{z,-1,1},PlotStyle->Thickness[0.01]]