This document will get you started using Mathematica. Mathematica is a general purpose CAS, useful for many things, but this document is geared towards linear algebra. Note that there is an extensive help facility built into Mathematica, complete with many examples. Commands are entered by pressing shift+enter on the keyboard (just hitting enter will give a new line which is still a continuation of the previous line). Putting a semi-colon at the end of the command will suppress the display of the output. Here are some simple examples.

345*57

357^85

The above is the traditional syntax. One can also use the 2D input: superscripts are entered by ctrl+^, and subscripts by ctrl+_ (use ctrl+space to leave the superscript/subscript position). We will use both forms in this document.

(357^85)

All functions acting on objects are entered using square brackets such as f[x,y]. Mathematica will keep exact precision until you tell it to numerically approximate. You use the N command to get a numerical approximation. We can also assign names to expressions so that we can re-use them.

a1=Sin[2/5]

N[a1,20]

a=(45^31)

b=(27^15)

N[Sqrt[a/b],20]

N[(b^(35/101)),20]

A few more examples.

c=a+b+2

FactorInteger[c]

p=(x^3)-127*(x^2)+31*x+2

p^3

Expand[(p^3)]

Before we get to linear algebra, we consider a few plotting examples.

Plot[p,{x,0,1}]

f=(x^3)-2*(x^2)*(2-y)-(y^2)

Plot3D[f,{x,-2,2},{y,-2,2}]

Plot3D[f,{x,-2,2},{y,-2,2},ColorFunction->"BlueGreenYellow",Mesh->{20,20}]

Now we turn to linear algebra. We first create a few matrices.

A={{2,5,7},{-3,8,11},{5,5,-6}}

Note that Mathematica does not display the matrix in 2D form by default. We must pipe the output to the MatrixForm command.

A//MatrixForm

B={{1,8,-1},{0,3,7},{-4,13,8}}

B//MatrixForm

A+B//MatrixForm

A.B//MatrixForm

Here is the 5th power of the matrix A. Note that entering A^5 will take the 5th power of each element, not what you want.

MatrixForm[MatrixPower[A,5]]

A.B-B.A//MatrixForm

We can introduce a shortcut for the MatrixForm command if we like.

MF=MatrixForm

MF[A+B]

Here is a random 5x5 matrix with integer entries

E1=RandomInteger[{-10,10},{5,5}]

E1//MatrixForm

M={{1,2,4,3,-1},{-1,-1,-3,-4,3},{-2,-4,-8,-5,3},{2,5,9,5,0}}

M//MF

The command RowReduce will put the matrix into reduced row-echelon form.

RowReduce[M]//MF

Here are a few more common matrix operations.

Det[E1]

A={{1,1,3},{0,-1,-1},{0,0,2}}

B={{0,2,1},{1,-1,0},{0,1,1}}

Det[B]

U=B.A.Inverse[B]

U//MF

The next command will give the eigenvalues and eigenvectors of the matrix U.

Eigensystem[U]

Eigenvalues[U]

Eigenvectors[U]

cp=CharacteristicPolynomial[U,x]

Factor[cp]

Individual elementary row operations can be done by using the “Part” command to works with the individual rows.

M//MF

We add 1 times the first row to the second row.

M2=M ; M2[[2]]=M2[[1]]+M2[[2]]

M2//MF

We add 2 times the first row to the second row.

M3=M2; M3[[3]]=2*M3[[1]]+M3[[3]]

M3//MF

We interchange the 1st and 2nd rows (for no particular reason).

M4=M3; M4[[{2,1}]]=M4[[{1,2}]]

M4//MF

M//MF

K=Table[0,{i,4},{j,8}]

K//MF

We use some commands that work with parts of a matrix.

K[[1;;4,1;;5]]=M

K//MF

B={{1,2,1},{3,4,5},{0,6,0},{-2,3,7}}

K[[1;;4,6;;8]]=B

K//MF

J=K[[2;;3,2;;4]]//MF

e1=3*x-4*y+7*z==2;e2=-2*x+7*y+3*z==7; e3=4*x+8*y-3*z==10;

{b,A}=CoefficientArrays[{e1,e2,e3},{x,y,z}];

A//MatrixForm

b//MatrixForm

Ag=Transpose[Append[Transpose[A],-b]]

Ag//MatrixForm

RowReduce[Ag]

Solve[{e1,e2,e3}]