We can watch what happens to the unit square in under matrix transformations. First, we need to describe the unit square parametrically.
![[Graphics:Images/chapter3_gr_2.gif]](Images/chapter3_gr_2.gif)
![[Graphics:Images/chapter3_gr_3.gif]](Images/chapter3_gr_3.gif)
![[Graphics:Images/chapter3_gr_6.gif]](Images/chapter3_gr_6.gif)
![[Graphics:Images/chapter3_gr_8.gif]](Images/chapter3_gr_8.gif)
In order to keep track of what gets transformed where, it would be better to color code the lines.
![[Graphics:Images/chapter3_gr_12.gif]](Images/chapter3_gr_12.gif)
![[Graphics:Images/chapter3_gr_14.gif]](Images/chapter3_gr_14.gif)
![[Graphics:Images/chapter3_gr_17.gif]](Images/chapter3_gr_17.gif)
![[Graphics:Images/chapter3_gr_18.gif]](Images/chapter3_gr_18.gif)
![[Graphics:Images/chapter3_gr_20.gif]](Images/chapter3_gr_20.gif)
We can set Mathematica so that it displays matrices in a more human readable form using the following trick.
![[Graphics:Images/chapter3_gr_23.gif]](Images/chapter3_gr_23.gif)
So if we enter a matrix like
![[Graphics:Images/chapter3_gr_25.gif]](Images/chapter3_gr_25.gif)
the result is displayed in matrix form rather than as a list of lists.
![[Graphics:Images/chapter3_gr_27.gif]](Images/chapter3_gr_27.gif)
![[Graphics:Images/chapter3_gr_29.gif]](Images/chapter3_gr_29.gif)
We can rotate the square by any given angle about the x-axis using the following matrix transformation.
![[Graphics:Images/chapter3_gr_32.gif]](Images/chapter3_gr_32.gif)
So, for example, if we use a specific angle, we get
![[Graphics:Images/chapter3_gr_33.gif]](Images/chapter3_gr_33.gif)
We can define
![[Graphics:Images/chapter3_gr_35.gif]](Images/chapter3_gr_35.gif)
![[Graphics:Images/chapter3_gr_36.gif]](Images/chapter3_gr_36.gif)
We can spin the square around the x-axis by graphing many different images as θ varies from 0 to 2π. This can be somewhat automated by loading an animation package.
![[Graphics:Images/chapter3_gr_39.gif]](Images/chapter3_gr_39.gif)
This package contains an Animate command that we can use to assemble the different graphs in a table. If you then select the entire table of output by clicking the mouse on the grouping bar on the right, Control-y (or Cell->Animate Selected Graphics) will begin the animation. The animation controls are in the lower left of the window.
![[Graphics:Images/chapter3_gr_40.gif]](Images/chapter3_gr_40.gif)
We will need the following package.
![[Graphics:Images/chapter3_gr_89.gif]](Images/chapter3_gr_89.gif)
You may find it useful to use the AppendRows or AppendColumns commands in the MatrixManipulation package.
![[Graphics:Images/chapter3_gr_90.gif]](Images/chapter3_gr_90.gif)
We can generate random numbers in the range 0 to 1 using the Random[] function (the range can be adjusted if desired). So putting three of these Random commands together will generate random vectors in 3-space. Then we can form their images my multiplying by M. Since the list will be long, you can suppress the output using a semi-colon at the end.
![[Graphics:Images/chapter3_gr_92.gif]](Images/chapter3_gr_92.gif)
![[Graphics:Images/chapter3_gr_93.gif]](Images/chapter3_gr_93.gif)
This shows that if you take points out of the unit cube in 3-space, their images under M all lie on a straight line going through the origin in the plane.
Notice that M has rank 1 and a 2-dimensional null space. These facts can be illustrated as follows.
Write the first column of M as a row vector
![[Graphics:Images/chapter3_gr_96.gif]](Images/chapter3_gr_96.gif)
![[Graphics:Images/chapter3_gr_99.gif]](Images/chapter3_gr_99.gif)
The rows of this matrix form a basis for the nullspace of M, so we can depict random linear combinations of the rows to get a graphical representation of the nullspace.
![[Graphics:Images/chapter3_gr_101.gif]](Images/chapter3_gr_101.gif)
The inverse of a square matrix can be computed with the Inverse command. We begin with a 5x5 matrix built from random integers selected between -10 and 10.
![[Graphics:Images/chapter3_gr_104.gif]](Images/chapter3_gr_104.gif)
The inverse is:
![[Graphics:Images/chapter3_gr_106.gif]](Images/chapter3_gr_106.gif)
If you prefer a decimal approximation, try
![[Graphics:Images/chapter3_gr_108.gif]](Images/chapter3_gr_108.gif)
To check that we have the inverse, we can compute:
![[Graphics:Images/chapter3_gr_110.gif]](Images/chapter3_gr_110.gif)
Here is a review of the different methods we have for solving linear systems in the context of Mathematica commands. Much of this material comes directly from the Mathematica help facility.We begin with a 2x2 coefficient matrix. Much of this material comes directly from the Mathematica help facility.
m = {{1, 5}, {2, 1}}
This gives two linear equations.
m . {x, y} == {a, b}
You can use Solve directly to solve these equations.
Solve[ %, {x, y} ]
You can also get the vector of solutions by calling LinearSolve. The result is equivalent to the one you get from Solve.
LinearSolve[m, {a, b}]
Another way to solve the equations is to invert the matrix m, and then multiply {a, b} by the inverse. This is not as efficient as using LinearSolve.
Inverse[m] . {a, b}
RowReduce performs a version of Gaussian elimination and can also be used to solve the equations.
RowReduce[{{1, 5, a}, {2, 1, b}}]
If you have a square matrix of maximal rank (and thus nullspace dimension 0), then you can always find a unique solution to the matrix equation
for any
. If, however, the matrix
has a non-trivial nullspace, then there may be either no vector, or an infinite number of vectors
which satisfy
for a particular
. This occurs when the linear equations embodied in
are not independent.
When has non-trivial nullspace, then it is always possible to find nonzero vectors
that satisfy
. The set of vectors
satisfying this equation form the null space of the matrix
by definition. Any of these vectors can be expressed as a linear combination of a particular set of basis vectors, which can be obtained using NullSpace[m].
Here is a simple matrix, corresponding to two identical linear equations.
m = {{1, 2}, {1, 2}}
LinearSolve cannot find a solution to the equation in this case.
LinearSolve[m, {a, b}]
There is a single basis vector for the null space of m.
NullSpace[ m ]
Multiplying the basis vector for the null space by m gives the zero vector.
m . %[[1]]
Here is a simple symbolic matrix with determinant zero.
m = {{a, b, c}, {2 a, 2 b, 2 c}, {3 a, 3 b, 3 c}}
The basis for the null space of m contains two vectors. Any linear combination of these vectors gives zero when multiplied by m.
NullSpace[ m ]
An important feature of LinearSolve and NullSpace is that they work with rectangular, as well as square, matrices.
When you represent a system of linear equations by a matrix equation of the form , the number of columns in
gives the number of variables, and the number of rows gives the number of equations. There are a number of cases.
Classes of linear systems represented by rectangular matrices.
This asks for the solution to the inconsistent set of equations and
.
LinearSolve[{{1}, {1}}, {1, 0}]
This matrix represents two equations, for three variables.
m = {{1, 3, 4}, {2, 1, 3}}
LinearSolve gives one of the possible solutions to this underdetermined set of equations.
v = LinearSolve[m, {1, 1}]
When a matrix represents an underdetermined system of equations, the matrix has a nontrivial null space. In this case, the null space is spanned by a single vector.
NullSpace[m]
If you take the solution you get from LinearSolve, and add any linear combination of the basis vectors for the null space, you still get a solution.
m . (v + 4 %[[1]])
Here are the four On Line exercises from section 3.4 in the text translated in Mathematica.
Let A be the matrix from exercise 2a on page 177. Use LinearSolve to solve the system A.X=B where
![[Graphics:Images/chapter3_gr_151.gif]](Images/chapter3_gr_151.gif)
Read the exercise in the text on page 182 and solve it in Mathematica.
Again, read the problem and solve in Mathematica. Be sure to enter the matrix using fractions rather than decimals to maintain the exactness in the calculations.
In this problem, you may find it useful to measure the magnitude of a vector (also called the norm). You can build a function for doing this.
![[Graphics:Images/chapter3_gr_153.gif]](Images/chapter3_gr_153.gif)
Now you can work the problem.