Introduction to Mathematica and
Linear Algebra
Getting Started
Start by loading the "Matrix Manipulation" package so that everything we want to
use is available.
Type <<LinearAlgebra`MatrixManipulation` (Note: The
apostrophes are backwards.)
Press Shift-Enter. There is no output for loading a package.
Basic Input
Lets create the matrix A =
. There are several ways to do this.
- Type A= then go to the "Input" menu (or right-click) and choose
"Create Table/Matrix/Palette..." Make sure "Matrix" is selected and
type in 3 Rows and 3 Columns. Click "OK"
- Click on the cell in position 1,1 and type "-1." Use Tab to move from
one cell to the next.
- Press Shift-Enter to complete it. Note the output. You could have typed it in
that way too.
- Type A//MatrixForm and execute it to take another look at A as a matrix.
Lets get the template for matrix B =
a different way.
- Type B= and go to the "File" menu, choose "Palettes," and
select "BasicCalculations." The palette window should appear on the right. Click
on the triangle next to "Lists and Matrices." Click the triangle next to
"Creating Lists and Matrices" if it is not already open.
- Select the palette button for creating a 2 × 2 matrix.
- In the main notebook window, place the cursor inside the matrix template. Press Ctrl-Enter
to add a row and press Ctrl-, (comma) to add a column. Type the entries for B
as you did A.
- Dont forget to press Shift-Enter to complete it.
Matrix Operations
Multiplication
- Multiply A and B by typing "A space B"
- Check your answer by doing the multiplication yourself.
- Now try multiplying A and B by typing "A.B" (period).
Whats the difference?
- What is the difference between B^2 and MatrixPower[B,2]?
Inverses
- Lets augment matrix A with I.
- Type: AppendRows[A, IdentityMatrix[3]] and execute.
- Oops! Lets name it. Go back and type F= in front of
"Append...." and re-execute.
- Type MatrixForm[F] to see it better.
(Note: Be careful not to define a matrix in Matrix Form. This can cause
syntax errors.)
- Now, type RowReduce[F]//MatrixForm to
reduce it and see it as a matrix.
- Type Ainv=TakeMatrix[%, {1,4},{3,6}] to define Ainv as the submatrix from
entry 1,4 through 3,6.
- Now multiply Ainv and A by typing Ainv. A
- What do you get? Does this make sense?
- Of course, this was the long method, but I hope you learned something along the way.
- You can also just type Inverse[A] and execute that.
- Find B -1.
Other Operations
Lets take another look at whats available in the palette.
- In the palette, scroll down to "Matrix Operations" and click the triangle to
open it if it isnt already.
- You can use the palette to do various operations or you can type them in directly.
- Try the following:
1. Find the trace of A and of B.
2. Find the transpose of B.
3. Use Mathematica to verify that (AB)T = B T
A T ¹ A T
B T for matrices A and B as defined
above.
Since B is singular, we need to change it to find the inverse.
Lets change b32 from 3 to 0.
Type: B = ReplacePart[B, 0, {3, 2}].
4. Use Mathematica to verify that (AB)-1 = B -1
A -1 ¹ A -1
B -1 for matrices A and B.
5. Use Mathematica to verify that (B -1)T
= (B T)-1 for the matrix B.
To calculate a determinant use Det[A].
6. Find det(A) and det(B)
7. Find det(AB) and det(A + B).
8. Find det(AT), det(BT), det(A-1),
det(B-1).
9. Make B the same as it was originally. Use "ReplacePart" to do so. Find
det(B).
10. What conclusions do you draw from these examples.
Exercises
Do the following Chapter 1 Supplementary Exercises (p.74):
1, 2, 8, 15, 16, 27, 9, 10, 12ab (Read and think about 12c), 19, 22
Return to
Abby Brown - Torrey Pines High School - 2/2002