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.
restart
withStudentLinearAlgebra:
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.
infolevelStudentLinearAlgebra ≔ 1:
Least-squares 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 (2-D case) or rectangular solids (3-D case) at each of the data points, whose area or volume represents the fit error at that point.
LeastSquaresPlot⁡1,1,2,3,4,2.5,5,4.1,6,7.2
Fitting curve: .8140e-1+.9663*x Least squares error: 2.339 Maximum error: 1.447
To specify a non-linear 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.
LeastSquaresPlot⁡1,1,2,3,4,2.5,5,4.1,6,7.2,x,y,curve=a⁢x3+b⁢x2+c⁢x+d
Fitting curve: -3.782+6.841*x-2.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 3-element 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.
LeastSquaresPlot⁡1,2,3,4,0.54,1.3,2.5,1.9,0.776,2.7,−0.6,0.3,boxoptions=color=blue
Fitting surface: 2.214+.5079e-1*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).
EigenPlot⁡1,12|13,35
Eigenvalue: 4/5+1/30*186^(1/2) Multiplicity: 1 Eigenvector: < 1.309, 1. > Eigenvalue: 4/5-1/30*186^(1/2) Multiplicity: 1 Eigenvector: < -.5093, 1. >
To see the input unit vectors as well, use the showunitvectors option.
EigenPlot⁡1,12|13,35,showunitvectors
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.
EigenPlot⁡−1,0|0,0
Eigenvalue: -1 Multiplicity: 1 Eigenvector: < 1, 0 > Eigenvalue: 0 Multiplicity: 1 Eigenvector: < 0, 1 >
In the 3-D 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.
EigenPlot⁡12,−53,0|0,43,0|−32,53,−1,axes=normal
Eigenvalue: -1 Multiplicity: 1 Eigenvector: < 1, 0, 1 > Eigenvalue: 1/2 Multiplicity: 1 Eigenvector: < 1/2, 1, 0 > Eigenvalue: 4/3 Multiplicity: 1 Eigenvector: < 0, 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.
EigenPlot⁡RotationMatrix⁡1
Eigenvalue: cos(1)+I*(1-cos(1)^2)^(1/2) Multiplicity: 1 Eigenvector: < .9997*I, 1. > Eigenvalue: cos(1)-I*(1-cos(1)^2)^(1/2) Multiplicity: 1 Eigenvector: < -.9997*I, 1. >
EigenPlot⁡1,0|1,1
Eigenvalue: 1 Multiplicity: 2 Eigenvector: < 1, 0 >
Return to Index of Example Worksheets
Download Help Document