LinearAlgebra Visualization  2
The visualization component of the Student[LinearAlgebra] subpackage contains routines that can be used to work with and visualize various concepts in an introductory linear algebra course. This worksheet demonstrates the basics of this functionality for problems involving least squares approximations and eigenvectors. The companion worksheet, LinearAlgebra Visualization  1, demonstrates the similar functionality for problems relating to vectors, planes, and linear systems.
For further information about the commands in the LinearAlgebra package, see the help page for that command. For a general overview, see LinearAlgebra.
Getting Started
Commands in the package can be referred to using the long form, that is, Student[LinearAlgebra][EigenPlot].
It is recommended to load the package first and then use the shorter command names.
>

$\mathrm{with}\left(\mathrm{Student}\left[\mathrm{LinearAlgebra}\right]\right)\:$

The following examples show how the various routines work.
Note: If you set either infolevel[Student] := 1 or infolevel[Student[LinearAlgebra]] := 1, many of the routines in this package provide additional information about the objects they are passed in the form of userinfo messages. This setting is recommended.
>

$\mathrm{infolevel}\left[\mathrm{Student}\left[\mathrm{LinearAlgebra}\right]\right]\u22541colon;$


Leastsquares Approximation


Visualizing the curve which best fits a given set of data in the least squares sense is accomplished through the LeastSquaresPlot command. By default, this command plots squares (2D case) or rectangular solids (3D case) at each of the data points, whose area or volume represents the fit error at that point.
>

$\mathrm{LeastSquaresPlot}\left(\left[\left[1\,1\right]\,\left[2\,3\right]\,\left[4\,2.5\right]\,\left[5\,4.1\right]\,\left[6\,7.2\right]\right]\right)$

Fitting curve: .8140e1+.9663*x
Least squares error: 2.339
Maximum error: 1.447
 
To specify a nonlinear fitting curve, use the curve option. Note: The unknowns in the problem (the coefficients of the curve) must appear only linearly in the curve expression.
>

$\mathrm{LeastSquaresPlot}\left(\left[\left[1\,1\right]\,\left[2\,3\right]\,\left[4\,2.5\right]\,\left[5\,4.1\right]\,\left[6\,7.2\right]\right]\,\left[x\,y\right]\,\mathrm{curve}\=a{x}^{3}\+b{x}^{2}\+cx\+d\right)$

Fitting curve: 3.782+6.841*x2.230*x^2+.2328*x^3
Least squares error: .4797
Maximum error: .3109
 
The data points can be given as a list of 2 or 3element lists (as in the above two examples), or as a pair or triple of lists, with each list giving the values for a given coordinate.
>

$\mathrm{LeastSquaresPlot}\left(\left[1\,2\,3\,4\right]\,\left[0.54\,1.3\,2.5\,1.9\right]\,\left[0.776\,2.7\,0.6\,0.3\right]\,\mathrm{boxoptions}\=\left[\mathrm{color}\=\mathrm{blue}\right]\right)$

Fitting surface: 2.214+.5079e1*x.9917*y
Least squares error: 2.000
Maximum error: 1.674
 


Eigenvectors


To illustrate the concepts of eigenvalues and eigenvectors, the EigenPlot command shows the action of a given square matrix on a selection of unit vectors emanating from the origin. These image vectors are drawn with their tails at the tips of the corresponding input unit vectors (to prevent the plot from being too cluttered). The eigenvectors of the matrix are unit vectors whose images under the action of the matrix are collinear with the original vectors. In the following plot, there are 2 eigenvectors, which are drawn in red and blue (the default colors).
>

$\mathrm{EigenPlot}\left(\u27e8\u27e81\,\frac{1}{2}\u27e9\\u27e8\frac{1}{3}\,\frac{3}{5}\u27e9\u27e9\right)$

Eigenvalue: 4/5+1/30*186^(1/2)
Multiplicity: 1
Eigenvector: < 1.309, 1. >
Eigenvalue: 4/51/30*186^(1/2)
Multiplicity: 1
Eigenvector: < .5093, 1. >
 
To see the input unit vectors as well, use the showunitvectors option.
>

$\mathrm{EigenPlot}\left(\u27e8\u27e81\,\frac{1}{2}\u27e9\\u27e8\frac{1}{3}\,\frac{3}{5}\u27e9\u27e9\,\mathrm{showunitvectors}\right)$

Eigenvalue: 4/5+1/30*186^(1/2)
Multiplicity: 1
Eigenvector: < 1.309, 1. >
Eigenvalue: 4/51/30*186^(1/2)
Multiplicity: 1
Eigenvector: < .5093, 1. >
 
Because the input vectors are unit vectors, the lengths and directions of the eigenvectors are determined by the corresponding eigenvalues. In the case of a 0 eigenvalue, the visual information about the corresponding eigenvector is therefore lost. To recover an indication of this, the eigenspaces are indicated by thin lines drawn in the same colors as the corresponding eigenvectors.
>

$\mathrm{EigenPlot}\left(\u27e8\u27e81\,0\u27e9\\u27e80\,0\u27e9\u27e9\right)$

Eigenvalue: 0
Multiplicity: 1
Eigenvector: < 0, 1 >
Eigenvalue: 1
Multiplicity: 1
Eigenvector: < 1, 0 >
 
In the 3D case, the eigenvectors corresponding to negative eigenvalues are shifted so that they remain outside the unit sphere. This reduces the visual clutter and allows you to see the action of the matrix more clearly.
>

$\mathrm{EigenPlot}\left(\u27e8\u27e8\frac{1}{2}\,\frac{5}{3}\,0\u27e9\\u27e80\,\frac{4}{3}\,0\u27e9\\u27e8\frac{3}{2}\,\frac{5}{3}\,1\u27e9\u27e9\,\mathrm{axes}\=\mathrm{normal}\right)$

Eigenvalue: 1
Multiplicity: 1
Eigenvector: < 1, 0, 1 >
Eigenvalue: 4/3
Multiplicity: 1
Eigenvector: < 0, 1, 0 >
Eigenvalue: 1/2
Multiplicity: 1
Eigenvector: < 1/2, 1, 0 >
 
Note: This command plots only real eigenvectors. Also, a matrix may have fewer eigenvectors than its dimension. For either of these reasons the plot may show fewer eigenvectors than might otherwise be expected.
>

$\mathrm{EigenPlot}\left(\mathrm{RotationMatrix}\left(1\right)\right)$

Eigenvalue: cos(1)+I*sin(1)
Multiplicity: 1
Eigenvector: < I, 1 >
Eigenvalue: cos(1)I*sin(1)
Multiplicity: 1
Eigenvector: < I, 1 >
 
>

$\mathrm{EigenPlot}\left(\u27e8\u27e81\,0\u27e9\\u27e81\,1\u27e9\u27e9\right)$

Eigenvalue: 1
Multiplicity: 2
Eigenvector: < 1, 0 >
 

Return to Index of Example Worksheets
