Chapter 1: A Panorama of Mathematica

The material is taken from relevant sections of Chapter 1 of Essentials of Mathematica With Applications to Mathematics and Physics by Nino Boccara, Springer (2007).  To expand the material under the section headings, double-click on the brackets on the right that look like arrows pointing down.

1.1 Notebooks and cells

The kernel is the software code or computer algorithm that performs computations. The front end is this page where you can write text, make graphics or send mathematical expressions for evaluation by the kernel.
The line below is an input cell illustrating simple addition.

3+5

The line above is the output cell. It gives the results of the operation that took place into the kernel.
This file is called a notebook and always has the extension .nb. You can create a notebook, save it and retrieve it for later work.

1.2 Basic Syntax and 1.3 Basic Operations

To write plain text like this, go to the Format / Style menu and select Text. A shortcut is Alt + 7. For Titles or Sections headings you can choose other options under the Format / Style menu. For example the section heading above "1.2 Basic Syntax" was created using the Section style. Try different text styles. You can also change the font and size of the text under Format / Show Fonts and Format / Size. 
When you are in a text mode you cannot perform mathematical operations. These expressions must be entered into an input cell.  If you hit the down you will automatically get into the Input style, that is the style for inputting mathematical expressions for the kernel to evaluate.

3+4

Hold the Shift key while pressing the Return key to evaluate an expression.

You can multiply numbers

3*4

Note that the letter x on the keyboard is not interpreted by the kernel as a multiplicative sign. Multiplications are done with the star (*) symbol or the × symbol that you can choose with the mouse from the Basic Math Assistant pallette, for example.

3×4

All symbols from the pallettes can also be produced with the keyboard instead of using the mouse. This can become covenient and quicker when you get use to it. There are two ways of doing this. To see this, hightlight the × symbol by dragging the cursor over it and press the Help key. In the Help description you'll see two other ways of creating this symbol. One method is to hit the following sequence:
Esc*Esc 
The other method is to enter the following command \[Times ] (but without a space before the closing bracket. I put the space here otherwise this sequence gets replaced by the times symbol).
However, for multiplication this is not really needed because multiplication can be done without any symbol. You must however put a space betwee the numbers. For example

3 4

has been interpreted by the kernel as 3 × 4, but the following

34

is really just the number 34.

In Mathematica you can assign values to variables. For example you can write

a=3

b=4

and then request the multiplication of a times b.

a b

Make sure you don't forget the space between the variables.  Otherwise, typing

ab

only creates a new variable called ab. This brings up the point that a variable name can have more than one letter. For example you can write

SpeedOfLight=3 10^8

ElectronMass=9.1 10^-31

Energy=ElectronMass SpeedOfLight^2

The exponent can be entered with the ^ symbol. To get a proper and nicer looking exponent you can use the Basic Math Assistant palette or you can type Ctrl ^ (holding down Ctrl while pressing Shift_6, or just 6). For example if you type a Ctrl^ 2  you will get this:

(a^2)

For instructions that we give to the kernel we don't always need to see the answer of every single step. For example, when we do such a simple operation as assigning a value to a variable we don't need to see the output from the kernel. A semicolon put at the end of the instruction tells Mathematica to perform the operation but not display the output. For example, compare the following

c=3;

with

d=4

This is convenient also because you can then assign more than one variables on a single line, spaced with the semicolon, as

e=7; f=8; g=9;

To divide you can use / or the palette(□/□)or Ctrl /, for example

e/f

or using the sequence to make a prettier division e Ctrl/ f

(e/f)

Note that by default Mathematica always return an exact answer when possible. This is why the results of e/f is returned as 7/8 not as 0.875. Here's another example. Let's ask Mathematica to divide 1 by 3, i.e.

(1/3)

Mathematica returns this because really 1/3 is a periodic decimal fraction. If we write that the answer is 0.333 we are in fact making an approximation. Approximations are nevertheless often needed. To force Mathematica to return an numerical value or approximation of a rational number use the function (or command) N which stands for numerical. 
All Mathematica functions or commands must follow the following syntax:
FunctionName[expression]
where FunctionName is the name of the Mathematica function (there are hundreds of them) and the expression must be in square brackets. This is important to remember because it is a common source of errors. When we write math we are more used to writing the expression or the argument of a function in normal parantheses but it must be in square brackets in Mathematica. 
Back to the numerical value. If we want an approximation of 1/3 we can use the function N as follow

N[(1/3)]

By default the function N returns 6 significant digits. If you want more or less digits you can specify it by adding an argument after the expression like this:

N[(1/3),10]

Here's another example this time with another function that calculates the square root of a number. The function is Sqrt.

Sqrt[5]

Or to get an approximation to 6 digits

N[Sqrt[5]]

Here two functions, N and Sqrt have been imbeded together. Note that all Mathematica function starts with a capital letter.
There are three important numbers that Mathematica can deal with directly, these are π, the exponential e and the imaginary number i. The number π can be entered either as Pi or selected with the palette or other shortcuts like Esc p Esc. For example to get π to 100 digits type

N[Pi,100]

But if you request only π you will get

Pi

Same thing with the exponential number. The exponential can be entered as E (not e), or the palette or other shortcuts

N[E]

N[E]

Finally the imaginary number can be entered as capital I, or palette or other shortcuts. Let's ask for (i^2)

I^2

or

(I^2)

Notice how the i taken from the palette is not exactly like the i from the keyboard. If you want to use the keybord enter I or Esc ii Esc.

1.5 Getting Help

To get help on a function type a question mark before the function name. For example to get help on the function N type ?N

?N

To get a more information type two question marks before the function name, i.e.

??N

You can also click with the mouse on >>  to get more information and examples. Try that.

You can also use the wildcard * to get help on all functions that starts with N. For example

?N*

And then click on the function you are looking for.  Putting the cursor on a function and pressing the Help key will also bring up documentation for that function.

1.6 Logical Operators

You can compare expressions and see if the result is True or False.  For example,

3>4

The sequence != gives a shortcut to the symbol ≠ (from the palette). You could also type explicitly the function Unequal, i.e.

Unequal[6,2*3]

To check for an equality you must use the double equal sign ==

4==3

Otherwise the kernel attemps to assign the value 3 to 4 which causes an error.

The logical operators are And, Or, Not, and Xor (for exclusive Or).  As is often the case with Mathematica these operators also have shortcuts. 
&& is equivalent to And
|| is equivalent to Or
! is equivalent to Not

For example,

4==2+2&&3≠5

In the texbook you'll notice that a series of instructions are often entered between curly brackets { }. For example,

{3>4,5==3+2}

Curly brackets are used to create lists. A list provides a useful way to manipulate groups of expressions as a whole. Each item of a list is seperated by a comma. In a list you can then execute a series of operations at once and obtain the results also in a list, as in the example above. Section 1.17 below deals more with lists and Chapter 5 in the textbook is devoted to lists.

1.7 Elementary Functions

All standard functions you can do on a simple calculator you can do in Mathematica. Functions like sine and cosine etc. For example,

Sin[Pi/4]

Or if you need the numerical value use the N function

N[Sin[Pi/4]]

Here's a list of a series of 3 operations

{Sinh[1.3], Cos[Pi], Tan[0.67]}

Sinh is the hyperbolic sine.

1.8 User-Defined Functions

The power of software like Mathematica is the ability to define your own functions. Before seeing how to define your own functions we need to understand the difference between two types of equal signs used in Mathematica.  
The standard equal sign = is also called the Set function. It is used to assign a value to a variable. For example,

a=8;

Let say now that we define another variable, say x,  that we want set to the value of a. To do this we can use the standard = sign and write

x=a

Which, as expected, returns the value of a that we set a few lines above. If later in our calculations the value of a changes, will the value of x be automatically updated? The answer is no. Let's try it by first changing the value of a

a=10;

and let's see what value x now has,

x

The value of x has not been updated even though a changes. 
If we wanted the value of x to be updated when a changes we need to define x with the other equal sign, noted :=, and called the SetDelayed function. Let's redo the same sequence of commands but this time by defining x with the := sign, i.e.

a=8;

x:=a

See already that with the use of := the value of x is not returned in an output cell eventhough there is no semi-colon at the end of the line. To get the value of x we need to request it explicitly, i.e.,

x

Now let change the value of a and ask for the value of x again.

a=10;

x

x has beed updated.

The textbook gives a similar example for illustrating the difference between = and := with the function Random, a built-in function that generates a random number each time you call the function. To learn more and see more examples type ?? :=

??:=

Defining you own function

Let's say you want to define the following function (using standard mathematical notation) :

f(x)=3x+5

The first thing to know is that in Mathematica, the parantheses in f (x) must be replaced by square brackets. The second thing we already saw is that it is preferable to use :=.  From this it would seem natural to write the function (1) with the following expression 
	f[x]:= 3 x + 5

This will not work as we want to. For a function to be defined properly in Mathematica the variable in the argument must be followed by an underscore. So, the correct way to express (1) in Mathematica language is as follow:

f[x_]:=3 x + 5

We can now use this function as you would use other built-in functions. For example, to find what is f(4) type

f[4]

You can also define a function of more than one variable, for example,

f[x_,y_]:=x^2+y

that we can evaluate for say f(4,5) using the following syntax,

f[4,5]

So remember these three rules when you define your own function:
Rule 1: The argument must be in square bracket. In fact this is the case for all Mathematica functions, either built-in or not. 
Rule 2: It is preferable to use the SetDelayed equal sign  := 
Rule 3: The argument of the function, i.e. the variable inside the square bracket, must be followed by the underscore sign. 
Examples:
	 f[x_] := a x  	(correct)
	 f[x_] = a x	(avoid, may lead to errors, though there may be times when just using = is useful)
	 f[x] = a x		(incorrect) 
	f(x_) := a x	(incorrect) 
	f(x) := a x	(incorrect)

1.9 Rules and Delayed Rules

If you define an expression and assign a value to one of its variable the expression is lost. For example,

2x+5

x=3

2x+5

The variable x has been replaced with the number 3 and the expression 2 x + 5 is lost, that is we cannot easily redo the calculation with say x = 5. The expression would need to be rewritten. In many cases we really only want to replace the variable with a value in order to see the results without losing the original expression. This can be done with a replacement rule. The command to do this is ReplaceAll. 
Before trying the ReplaceAll function on the expression above (i.e. 2 x + 5) we need to learn something else. In many cases it is very important that before doing a new calculation you clear from memory the variables that you are going to use. Many errors in doing calculations in Mathematica arise because we may be dealing with variables that have conflicting definitions. To clear one or more variables from memory use the function Clear. For the purposes of the example that follows it is necessary to clear the variable x from memory because currently the variable x has been assigned the value 3. For example, if we request the value of x we will get 3,

x

Let's now clear x from memory,

Clear[x]

or simply

x=.

and ask for x again

x

We see that there is no value assigned to x anymore. We can now do the ReplaceAll example.

ReplaceAll[2x+5,x->2]

This tells to replace x by the value of 2 in the expression 2 x + 5. Note that the replacement rule is done with the arrow, not the equal sign. The arrow can be made by typing a dash - followed by the greater than sign >. Note that this did not assign a value to x. Let's check this,

x

x can also be replaced with another variable, say z

ReplaceAll[2x+5,x->z]

The ReplaceAll function can be used more effectively by using the shortcut /.

2x+5/.x->z

The replacement rule can be chained. For example,

2x+5/.x->z/.z->6

You can also replace more than one variable at once by assiging the replacement rules inside a list, i.e. under curly brackets. For example,

2 x+z/.{x->2,z->c}

1.11 Plotting

Mathematica can do advanced graphics. We'll look at this into more details throughout this course. Plotting is an important part of Computational Mechanics. In this course you will learn to do proferssional looking graphics.
For plotting two-dimensional analytical functions the command is Plot. The command Plot is used for plotting continuous function. It is not for plotting a set of discrete measurements. We will see this later in the course.
For example, let's say you want to plot the following function

f(x)=(e^x)

in the interval  -2 ≤ x ≤ 2. Here's the syntax

Plot[(E^x),{x,-2,2}]

As seen in Section 1.8 you can also first define your own function and plot it later like this

f[x_]:=(E^x)

Plot[f[x],{x,-2,2}]

You can plot more than one function on a single graph. Say you want to plot these two functions:

f(x)=(e^x) and g(x)=3(x^2)+5

Let's define the g(x) function (we have already defined f(x), so there is no need to redefine it; it is still in memory):

g[x_]:=3(x^2)+5

The syntax to plot two functions is as follow:

Plot[{f[x],g[x]},{x,-2,2}]

Of course we can customize the graph by adding labels, titles, changing the line styles, etc. We will not see all options at this point. You will learn them throughout the course. However, for this course, and in Physics in general, a graph is not acceptable without axis labels (and units). So we will see how to make these now. Here's the syntax to add axes labels and units assuming the function f(x) represents the position of an object as a function of time:

Plot[f[x],{x,-2,2},AxesLabel->{"t (s)","x (m)"}]

Mathematica can also do 3D plotting of continuous functions with the command Plot3D. For example,

Plot3D[Sin[x] Cos[2y],{x,-2,2},{y,-2,2},AxesLabel->{"t (s)","x (m)","y(m)"}]

1.12 Solving Equations

You can solve an equation or a set of equations with the command Solve. For example, you can solve the following quadratic equation for the variable x
	a (x^2)+b x + c = 0 
like this

Remove["Global`*"] (* See section 1.19 for the use of this command Remove *)

Solve[a (x^2)+b x + c==0,x]

Note that you need to use here the double equal sign.
You can solve a system of equations. For example, this system of equations
	2x-4y=3
x+5y=-2
can be solved like this:

Solve[{2x-y==3,x+5y==-2},{x,y}]

You see that the command Solve gives the exact solution of the problem (i.e. 13/11 instead of an approximation like 1.18.
The fact that the solve command generates exact solutions limits its usefulness to simple problems. Even when Solve can obtain a solution it is sometimes so complicated as to be almost useless. 
Consider solving the following equation for x:

(x^3)-4x+2=0

A good practice to adopt before solving an equation like this if to first plot the equation to see how it looks like. Let's first define it:

h[x_]:=(x^3)-4x+2

and then plot it

Plot[h[x],{x,-3,3}]

We see visually that this equations has 3 roots, one around -2.2, one around 0.5 and another one around 1.7. Let's now try to find these roots with the command Solve:

Solve[h[x]==0,x]

While the Solve command has been able to generate the three solutions to the equation, the solutions reveal little. In fact they even seem to indicate that the solutions are complex.

Often in studying physical systems we do not require an exact solution and will settle for an approximate solution. In addition to the Solve command there is the NSolve command which gives a numerical solution. For example,

NSolve[h[x]==0,x]

Using NSolve you can obtain the solutions to any arbitrary degree of precision, by specifying the number of digits you need as a third argument. For example,

NSolve[h[x]==0,x,20]

We will learn later in this course how computers can find numerical solutions to complex problems. For now, let's just accept that computer softwares can find solutions to problems numerically as opposed to analytically.

Equations with functions such as cosine, sine and log are referred to as transcendental equations. Solving transcendental equations is complicated by the fact that they can have many, possibly infinitely many, solutions. This can create problems for NSolve. Consider the following equation 
	cos(θ)=θ, 
and let's try to use the command Solve that will attempt to solve this equation analytically for θ, i.e.

Solve[Cos[θ]==θ,θ]

We get an error message. Let's try the command NSolve instead that will attempt to solve the problem numerically

NSolve[Cos[θ]==θ,θ]

Again, the same error message. As a good practice to adopt let's see visually if there seem to be a solution to this problem. This can be done by plotting the functions f(θ)=cos(θ) and f(θ)=θ on a same graph, i.e.

Plot[{Cos[θ],θ},{θ,-Pi,Pi},AxesLabel->{"θ","f(θ)"}]

We see visually that there is a solution at around θ=0.8. How can we get a closer approximation to this problem? To obtain reliable solutions to transcendental equations we need to use another of Mathematica's root finding routines called FindRoot.

FindRoot[Cos[θ]==θ,{θ,0.8}]

In the argument {θ, 0.8} the 0.8 represents a guess of the solution of the problem.

Note that the arguments used by FindRoot command differ from those of NSolve. NSolve had two arguments, the equation you wish to solve and the variable you wish to solve for. FindRoot, on the other hand, has three arguments the equation you wish to solve, the variable you wish to solve for and an estimate of the solution, in this case 0.8. FindRoot works by refining this initial guess through a process known as iteration.

The question arises whether one should use NSolve or FindRoot to determine the numerical solution of  particular equation. Irrespective of which routine you choose you should always investigate the problem graphically to determine the number and the approximate location of the solutions. This done, try using NSolve first, if that works then the problem is solved. If that doesn't work or if it is unable to locate all the roots then switch to FindRoot.

1.13 Derivatives and Integrals

Derivatives

To differientiate a function you can use the prime ', the command D or Derivative or use the partial derivative symbol from the BasicMathInput palette. For example, let's create a function, say

f[x_]:=(x^3)+2Cos[x]

We can differientiate once

f'[x]

or twice

f''[x]

We can alternatively use the following syntax

D[f[x],x]

or twice with

D[f[x],{x,2}]

Or you can use the following command

Derivative[2][f][x]

Or even use the palette

(∂_x) f[x]

You can do partial derivatives, for example

D[(x^4)Cos[y],{x,1}]

Or

D[(x^4)Cos[y],{x,1},{y,2}]

Integration

The command to integrate is Integrate or you can use the integral symbol from the palette. For example,

∫x Cos[x]\[DifferentialD]x

Or

Integrate[x Cos[x],x]

You can do a definite integral like this

(∫_0^2)x Cos[x]\[DifferentialD]x

or like this

Integrate[x Cos[x],{x,0,2}]

Numerical Integration

Some functions are too complicated to be integrated analytically. For example, Mathematica can evaluate analytically the following indefinite integral

∫ (E^(-(Sqrt[x])))\[DifferentialD]x

But does not know how to evaluate the following one

∫ (E^(-(Sqrt[x+(x^2)])))\[DifferentialD]x

Note how the output expression is the same as the input. This is a way of saying that Mathematica cannot do the integration.
Making the integral definite does not help Mathematica find the solution, e.g.,

(∫_0^1)(E^(-(Sqrt[x+(x^2)])))\[DifferentialD]x

But, remember that a definite integral is like calculating the area under a function between two limits. How complicated is that function? Let's plot it say between 0 and 3,

Plot[{(E^(-(Sqrt[x+(x^2)])))},{x,0,3},AxesLabel->{"x","f(x)"}]

Can't we evaluate the area under the curve in the interval [0 1], or more generally in the interval [a b]? This doesn't seem all that complicated. We can certainly estimate it using a numerical algorithm. Mathematica can perform numerical integrations with the command NIntegrate. However, numerical integrations can only be done for definite integrals since there are no known analytical solutions. For example, the previous integral can be evaluated using the following syntax:

NIntegrate[(E^(-(Sqrt[x+(x^2)]))),{x,0,1}]

Another way is to use the integral sign within the N command like this

N[(∫_0^1)(E^(-(Sqrt[x+(x^2)])))\[DifferentialD]x]

Or a shortcut to this last command is

(∫_0^1)(E^(-(Sqrt[x+(x^2)])))\[DifferentialD]x//N

We will learn in this course a few basic algorithms used for numerical integration.

1.14 Series Expansions and Limits

The command Series generates a Taylor series for any function. For the syntax type ?Series, i.e.

?Series

For example, the Taylor series expansion of sin(θ) about θ=0 to 5th order is,

Series[Sin[θ],{θ,0,5}]

You can take the limit of an expression with the command Limit, for example

Limit[(1/x),x->∞]

Also read the other examples in the textbook.

1.15 Discrete Sums

You can use the command Sum or the symbol ∑ from the palette to make discrete sums. for example,

Sum[(n^2),{n,0,10}]

which is equivalent to

(∑_(n=0)^10)(n^2)   (* This is a lot clearer than the Sum command*)

1.16  Ordinary Differential Equations

Solving differential equations, ordinary and partial, is perhaps the most important aspect of Computational Physics. Some ordinary differential equations (ODE) can be solved analytically. Mathematica can do that with the command DSolve. For example, imagine you need to find the solution to this ODE
	(dy/dx)+2y=2
This can be done with the following syntax:

Remove["Global`*"]

DSolve[y'[x]+2y[x]==2,y[x],x]

The symbol C[1] represents a constant. The value of such a constant of integration can only be determined with the initial or boundary conditions of the problem. 
Here's a simple example taken from physics. Suppose you let an object fall under the action of gravity from rest and from a given height (Subscript[y, 0]). There is no air resistance. What is the position of the object as a function of time, i.e. find y(t)? This problem can be posed as an ODE with initial conditions. The ODE is the following
	(((d^2)y)/(dt^2))=-g			(1)
with the following initial conditions
	y(0)=(Subscript[y, 0]) 			(2)	(initial position of the object)
	v(0)=(dy/dt)=0 at t=0		(3)	(initial velocity of the object).
We can solve this problem with the command DSolve like this

Remove["Global`*"]

DSolve[{y''[t]==-g,y[0]==y0,y'[0]==0},y[t],t]

See how equations (1), (2) and (3) are entered as a list of 3 equations into the command DSolve. The answer returned is within a list and is returned with a syntax like:{{y[t]->(1/2) (-g (t^2)+2 y0)}}
It would be more convenient if the answer could be returned to a function, say Y[t_]. This could be done with the replacement rule /. employed like this:

Y[t_]=y[t]/.DSolve[{y''[t]==-g,y[0]==y0,y'[0]==0},y[t],t]//First

(Some comments.  The //First is added in order to take the first element of the output list, i.e. doing so removes extraneous {} from our solution.  Try it without the //First.  We have used Y[t_] instead of y[t_] in order to avoid using the same symbol on both sides of the assignment.  It would work once using the same symbol, but re-entering the line would result in errors because y[t] on the RHS would already be defined.  (Try it.)  Also, we have used = instead of := .  If we had used :=, and wanted Y[2], Mathematica would try to integrate the equation with respect the variable "2", which doesn't make sense.  We could get around this by using something like

Y[t_] := Module[{x},y[x]/.DSolve[{y''[x] == -g, y[0] == y0, y'[0] == 0}, y[x], x] /. x -> t // First]

but this is more complicated.  Additionally, every time you would want Y[t] for a certain value of t, the right hand side would be re-evaluated, i.e. the ODE would be solved again, and that can get slow.)

Or if you find this clearer you can explicitly use the command ReplaceAll like this

Remove["Global`*"]

Y[t_]=ReplaceAll[y[t],DSolve[{y''[t]==-g,y[0]==y0,y'[0]==0},y[t],t]]//First

With this syntax we now have in memory a function Y[t] that is

Y[t]

If you are interested in the height at a specific time you can assign the values of the constants of the problem and request the height at a given time, say at t=10 s for an object released from a height of (Subscript[h, 0])=1000 m in a gravitational field with g=9.8 m/(s^2). This could be done like this:

y0=1000;g=9.81;Y[10]

As with integration, most ODE's can't be solved analytically.  The built-in numerical ODE solver in Mathematica is NDSolve.  When using NDSolve, it is necessary to including the domain on which you are solving, and all parameters must be assigned numerical values.

YN[t_]=y[t]/.NDSolve[{y''[t]==-g,y[0]==y0,y'[0]==0},y[t],{t,0,10}]//First

Plot[YN[t],{t,0,10}]

The numerical solution is of course approximate and differs from the analytical solution, e.g.

YN[10]-Y[10]

1.17 Lists

It is important to become familiar with manipulating and generating lists with Mathematica. A list is a series of variables or numbers within curly brackets. 
Here's the easiest way of generating a list of numbers, for example,

MyList={5,34,89,2,100}

You can do many operations on a list. You can for example sort the list with the command Sort

Sort[MyList]

By default the list is sorted in ascending order. You could sort it in descending order with the addition of the argument Greater:

Sort[MyList,Greater]

You can check the number of elements in the list with the command Length

Length[MyList]

You can grab only one element of the list by specifying the index of the list within two square brackets. For example, let say you need the second element of the list, i.e. the number 34. You can type

MyList[[2]]

You can do mathematical operations on each element of the list at once. For example you can square all element of the list simply like this:

(MyList^2)

Or take the log

N[Log[MyList]]

Or many other mathematical operations.

There is an important command that we will use very often in this course for generating list. If you only have a few numbers you can generate a list like we did at the top of this section. However, often long lists will need to be created automatically. The command for generating automatic lists is Table.

For example, there is a command called Random that can be used to generate a random number. The command Random[] generates by default a real random number between 0 and 1. For example,

Random[]

If you want a random real number in a specific range, i.e. not necessarily between 0 and 1 but say between 100 and 200 you have to use the following syntax

Random[Real,{100,200}]

The first argument tells that you want a real number. You may however require an integer random number. In this case use the following syntax

Random[Integer,{100,200}]

Ok, back to the list now. Let’s say you need a list of 10 real random numbers. You can use the command Table to generate this list automatically for you with the following syntax:

Table[Random[],{10}]

The first argument is the function that you want to use to generate the list, here Random[], and the second argument tells the number of times you want this function to be executed, here 10 times.
More generally, the command Table is used with the following arguments: Table[f(x), {x, xmin, xmax, increment}]. For example, let say you want a list of the sine function evaluated at: 0, π/4, π/2, 3π/4, π, 5π/4, 3π/2, 7π/4, 2π. To do this you would use the following syntax:

SineList=Table[Sin[x],{x,0,2π,π/4}]

Make sure you understand this syntax. Explore on your own the command Range which can be used to generate a simple list of integers.

We saw in Section 1.11 how to make graphs of analytical functions with the command Plot. Often in this course we will need to also plot list of discrete data instead of continuous functions. In this case the command Plot will not work. To plot a series of discrete data, i.e. a list, we need to use the command ListPlot.
Here's an example taken from the textbook. Let's first mimic a series of measurements taken from some sort of instrument. Such measurements will have some random contribution due to inherent noise present in all instrumentation. Let's say we are measuring some sort of wavy motion that behaves like a cosine signal. We can generate such a list like this

data=Table[{x,Cos[x]+0.25Random[]},{x,0,2Pi,0.2}]

Note how this list now is really a series of small lists made of two elements within a larger list. This can be interpreted as a table of values. This format in Mathematica {{a,b},{c,d},{e,f},...} can be interpreted as a table like this
a  b
c  d
e  f
...
where the first column in this case is the independant variable, i.e. x, and the second column is the function, here cos(x)+some random noise. 
To plot a list of data like this use the command ListPlot like this:

ListPlot[data]

You can add axes labels like you would do with the Plot command, i.e.,

ListPlot[data,AxesLabel->{"x","f(x)"}]

The textbook also shows how to make a fit to such data. We will see data fitting in greater details later in this course. You can skip this part at this point.

You can also import data from a file with the command Import. Most commonly you will need to load data contained in a two-column text file into a list, where the first column is the independant variable, say time, and the second column the dependant variable, say position. If the name of the file that contains the data has the extension .dat then all you have to type is
	MyList = Import["filename.dat"];
where filename is the actual name of the file and can be anything. This will create a two column matrix that you can later manipulate and plot with the command ListPlot.
For this to work the data must be in the current working directory. To see the current working directory type Directory []

Directory[]

If this is not where you data file is located you can change the working directory by specifying the path of the directory within the command SetDirectory. For example,

SetDirectory["Desktop"]

1.18 Vectors and Matrices

An n-dimensional vector is really a list of n-elements. For example,we can create a 3-dimensional vector like this

Remove["Global`*"]

vector1={x1,y1,z1};

We can multiply this vector by a scalar, e.g. by the scalar a

a vector1

You can add two vectors, e.g.,

vector2={x2,y2,z2};

vector1+vector2

You can also perform a dot product with the command Dot or using the actual dot

vector1.vector2

You can also do a cross product with the command Cross like this,

Cross[vector1,vector2]

You can also create and manipulate matrices. A matrix is in fact a list of lists. For example, the following command will create a matrix from the vectors created above:

mat={vector1,vector2}

If you would like the output to visually look more like a matrix you can use the command MatrixForm, for example

MatrixForm[mat]

You can transpose a matrix with the command Transpose

Transpose[mat]//MatrixForm

Note that I used a shortcut to the command MatrixForm.
You can also invert an n×n matrix with the command Inverse, e.g.,

mat={{2,0,7},{4,12,3},{7,7,0}};
matinv=Inverse[mat]

You can check if this is really the inverse by multiplying the result by the original matrix. You should get the identity matrix.

mat.matinv//MatrixForm

1.19 Clear, ClearAll and Remove

When defining new variables these are stored in the computer memory. These variables and their associated values will remain in memory unless you explicitly clear the variable from memory. The command to clear variables from memory is Clear. For example, let say you assign a values to symbols, somethin glike:

a=6;b=7;MyAge=22;

If you request the values of these variables you get

{a,b,MyAge}

Now you can clear the value of each of these variables like this

Clear[a]

If you request the values of the variables again you get:

{a,b,MyAge}

You can check the variables you have previously created and that are stored in memory with the command Names. To get the list of all variables stored in memory use the argument Global with the following syntax:

Names["Global`*"]

This commands basically ask for all global variables stored in memory. The star is a wildcard that mean all. 
So although we have explicitly erased, or cleared, the content of the symbol a, the variable still exists in memory. There is however no value associated with it because we cleared it.  
To actually clear the value of a variable as well as removing the symbol from memory use instead the command Remove. For example,

Remove[a]

Names["Global`*"]

We see this time that the symbol a has been removed from memory.

It is highly recommended that before starting a new problem you remove all variables from memory in order to avoid interference with previous values or function definitions. Not doing so often leads to bugs in your code. To remove all variables from memory use the following syntax:

Remove["Global`*"]

Names["Global`*"]

The memory is empty. This is a safe method to adopt before starting any new problem.

1.20 Packages

When you launch Mathematica you get by default a large number of commands but you don't get all commands available. Some more specialized commands need to be explicitly loaded in memory by the user. These extra commands or functionality are stored in packages. Each of these packages has a different name. To use them you need to use the command Needs and enter the name of the package as the argument. 
For example, there is a package that contains physical constants. The package is called PhysicalConstants and can be loaded like this:

Needs["PhysicalConstants`"]

To see what's in this package use the command Names with the name of the package as the argument, i.e.,

Names["PhysicalConstants`*"]

This shows that this package contains a bunch of physical constants. This could be useful instead of searching textbooks for the values of these variables. For example, you can get the gravitational acceleration is the variable call AccelerationDueToGravity, i.e.,

AccelerationDueToGravity

Note how the variable is entered in memory with the units Meter/(Second^2). In Mathematica you can therefore manipulate numbers with their associated units. The units are really just symbols that are treated as any other symbols. For example, you can calculate the rest energy of an electron like this:

Energy=ElectronMass (SpeedOfLight^2)

and the answer is returned with the appropriate units. However, Mathematica does not know here that this special combination of units is also referred to as Joule.

The syntax << can be used as a shortcut to the command Needs, i.e.

Remove["Global`*"]
<<PhysicalConstants`

and check if the constant EarthRadius exists:

EarthRadius