Linear Algebra

Commands
for
Linear Algebra

By 
Dennis M. Schneider

With Assistance From
Robby Villegas

Copyright 1990-92 by Dennis M. Schneider
Work on this package partially supported by grants from
Pew Charitable Trusts
National Science Foundation
NSF-ILI Grant # USE-9050757
NSF Grant # USE-9153249
Knox College
Lilly Foundation

Initialization

This notebook contains examples for the commands contained in the package LinearAlgebra.m. That package is in the folder KnoxPackages which must be loaded in the Packages folder in the Mathematica folder.

Needs["KnoxPackages`LinearAlgebra`"]

Examples

AppendColumn

AppendColumn[{{1,2,3},{2,3,4},{4,5,6}},{{a,b,c},{d,e,f}}]

AppendRow

AppendRow[{{1,2,3},{2,3,4},{4,5,6}},{{a,b,c},{d,e,f}}]

PivotColumns

PivotColumns[{{1,3,-2,1},{2,6,-2,8},{-1,-3,8,17}}]

ColumnSpace

ColumnSpace[{{1,3,-2,1},{2,6,-2,8},{-1,-3,8,17}}]

Rank

Rank[{{1,3,-2,1},{2,6,-2,8},{-1,-3,8,17}}]

RowSpace

RowSpace[{{1,3,-2,1},{2,6,-2,8},{-1,-3,8,17}}]

RowSpace[{{I,1,1,0},{1+I,0,0,1}}]

HilbertMatrix

?HilbertMatrix

HilbertMatrix[5,6]

HilbertMatrix[5]

GramSchmidt

?GramSchmidt

?NDot

GramSchmidt[{{-1,0,1},{-1,1,0}}]

GramSchmidt[{{-1,0,1},{-1,1,0}},Normalized->True]

GramSchmidt[{{-1,0,1},{-1,1,0}},InnerProduct->NDot,Normalized->True]

GramSchmidt[{{-1,0,1},{-1,Pi,0}},InnerProduct->NDot]

GramSchmidt[{{a,b},{c,d}}]

hilbertmat10 = HilbertMatrix[10];

GramSchmidt[hilbertmat10,InnerProduct->NDot]

Length[%]

GramSchmidt[hilbertmat10,InnerProduct->NDot,Tolerance->10^-6]

Length[%]

GramSchmidt[{1,x,x^2},InnerProduct->FunctionDot[{x,0,1}],Normalized->True]

GramSchmidt[{1,x,x^2},InnerProduct->NFunctionDot[{x,0,1}],Normalized->True]

GramSchmidt[{Sin[x] Cos[x],Sin[2x],x},InnerProduct->FunctionDot[{x,0,1}]]

GramSchmidt[{Sin[x] Cos[x],Sin[2x],x},InnerProduct->NFunctionDot[{x,0,1}]]

GramSchmidt[{{0,0,0}}]

Project

Project[{-1,-1,1,1},{{1,0,1,1},{0,1,1,2},{2,-2,0,-2}}]

Projection Matrix

ProjectionMatrix[{{1,0,1,1},{0,1,1,2},{2,-2,0,-2}}]

LeastSquaresSoln

LeastSquaresSoln[{{1,0,2},{0,1,-2},{1,1,0},{1,2,-2}},
	{-1,-1,1,1}]

LeastSquaresSoln[{{1,-1},{2,1},{3,2}},
	{-3,0,6}]

The optimal least-squares solution can be found using Mathematica's PseudoInverse command.  It will agree with LeastSquaresSoln when the matrix has maximal rank.

PseudoInverse[{{1,0,2},{0,1,-2},{1,1,0},{1,2,-2}}].{-1,-1,1,1}

PseudoInverse[{{1,-1},{2,1},{3,2}}].{-3,0,6}

DiagQuad

DiagQuad[x^2 + x y + y^2,{x,y},{u,v}]

DiagQuad[x y + y z + x z,{x,y,z},{u,v,w}]

DiagQuad[x y + y z + x z,{x,y,z},{u,v,w}]

Diagonalizing the quadratic using numerical coefficients leads to a different ordering of the eigenvalues and a different bases of eigenvectors.

NDiagQuad[x y + y z + x z,{x,y,z},{u,v,w}]

DiagQuad[x^2 + x y + y z + x z,{x,y,z},{u,v,w}]

NDiagQuad[x^2 + x y + y z + x z,{x,y,z},{u,v,w}]

CompleteSquare

CompleteSquare[x^2 + x + 2y^2 + 7y - 14,{x}]

CompleteSquare[x^2 + x + 2y^2 + 7y - 14,{y}]

CompleteSquare[x^2 + x + 2y^2 + 7y - 14,{x,y}]

CompleteSquare[(a + c)^3 x^2 + b x + 2Pi y^2 + 7y - 14 +
	z^3 + (x + z)^4,{x,y}]

CompleteSquare[(a + b)^2 x^2 + c x + (d + x)^2 +
					(y + c + d)^2 + y,{x,y}]

CompleteSquare[Exp[x^2] + c x,{x}]

Random Vectors and Matrices of Various Types

RandomVector

RandomVector[4]

RandomVector[4,Integer,{-2,4}]

RandomMatrix

RandomMatrix[3]

RandomMatrix[3,Integer,{-4,10}]

RandomMatrix[3,Integer,{-4,1},MatRank->2]

RandomSymmetricMatrix

RandomSymmetricMatrix[3]

RandomSymmetricMatrix[3, Integer, {-3,6}]

RandomTriangularMatrix

RandomTriangularMatrix[5]

RandomTriangularMatrix[5,Integer,{-2,12}]

RandomOrthogonalMatrix

RandomOrthogonalMatrix[3]

RandomOrthogonalMatrix[3,Integer,{-2,5}]

RandomPermutationMatrix

RandomPermutationMatrix[5]

RandomNonsingularMatrix

RandomNonsingularMatrix[3]

RandomNonsingularMatrix[3, Integer, {-3,3}]

RandomSingularMatrix

RandomSingularMatrix[3,Integer,{0,2}]