Strang Linear Algebra Package
 Introduction

By Allan Hayes

Copyright Allan Hayes 1993-94

Permission is hereby granted to modify and/or make copies of this file for any purpose other than direct profit, or as part of a commercial product, provided this copyright notice is left intact.  Sale, other than for the cost of media, is prohibited. Permission is hereby granted to reproduce part or all of this file, provided that the source is acknowledged.

A package to support the the textbook	
Introduction to Linear Algebra
by
Gilbert Strang

Please send Suggestions and Comments

Suggestions and Comments on all aspects of this package will be very welcome .
In particular I would like to get some idea about whether it is of enough interest to 
warrant putting more time into development.
I have my own doubts about the  rdemonstrating rather than interactive nature of the format

Two questions:
(1) Would it be useful to have a stripped down version of the code for
students to read, containing the bare computation instructions?
(2) Should students construct their own code?

General comments about what is needed in using Mathematica for  teaching/learning/using
linear algebra would be helpful in the preparation of other notebooks

Allan Hayes
12, Copse Close
Oadby
Leicester LE2 4FB
Tel&Fax:+44(0)533-714198
Email : hay@le.ac.uk 
	    hay@haystack.demon.co.uk(NEXTMAIL)

Using this Notebook

Input cells have text in bold courier. 
	to compute:
	click on the text, or  in the cell or on the cell bracket;
	then key in  Shift+Return (or Command+Return or Enter).

LOAD THE PACKAGE

<<StrangLinearAlgebra`

GENERAL INFORMATION

?StrangLinearAlgebraInfo

Alternatively you can look up in the the Function Browser  by selecting the text  (not the question mark) and keying  Command+F ( = Command + Shift + f).
At the moment the examples cannot be pasted in from the browser - this needs attention.

ERRORS, FAILURES AND MESSAGES

Each function is set up so that if it receives unaccepable input it returns the input unaltered and issues a message specifying the problem. Here are two examples.

basis[1]

basis[{{1}},2]

OPTIONS

Most of the functions have options  that modify their output. These are  explained in the online information for each function. For example , the option  Explain -> True causes some explanation of the computation to be generated.
Several options can be included, in any order; but they must come after the other entries. If an option is  repeated only its  first occurrence is effective.

The  Functions

Each of the following cell tests the on-line information and examples . 
Much more could be done – a symbolic example given in the appendix shows one way.

In the next version more automatic simplification of symbolic expressions will probably be introduced.

basis

?basis

basis[{{1,2,3,4},{2,1,3,1},{1,1,2,3}}]

basis[{{1,2,3,4},{2,1,3,1},{1,1,2,3}}, Explain->True]

cofactor

?cofactor

cofactor[{{1,2,3},{2,-1,3},{1,1,2}}]

cofactor[{{1,2,3},{2,-1,3},{1,1,2}}, Explain->True]

cofactor[{{1,2,3},{2,-1,3},{1,1,2}}, Explain->PatternOnly]

cramer

?cramer

cramer[{{1,2,3},{2,-1,3},{1,1,2}}, {1,2,3}]

cramer[{{1,2,3},{2,-1,3},{1,1,2}}, {1,2,3}, Explain->True]

determ

?determ

determ[{{1,2,3},{2,-1,3},{1,1,2}}]

determ[{{1,2,3},{2,-1,3},{1,1,2}}, Explain->True]

determ[{{1,2,3},{2,-1,3},{1,1,2}}, Explain->PatternOnly]

eigen

?eigen

eigen[{{1,0,3},{2,-1,3},{1,1,2}}]

eigen[{{1,0,3},{2,-1,3},{1,1,2}}, Explain->True]

eigen2

?eigen2

eigen2[{{1,2},{1,1}}]

eigen2[{{1,2},{1,1}}, Explain->True]

findpiv

?findpiv

findpiv[{{1,2,3,4},{0,0,0,2},{0,0,1,1}},2,2]

findpiv[{{1,2,3,4},{0,0,0,2},{0,0,1,1}},2,2, Explain->True]

findpiv[{{1,2,3,4},{0,0,0,2},{0,0,1,1}},2,2, Explain->PatternOnly]

findpiv[{{1,2,3,4},{0,0,0,0},{2,0,0,0}},2,2, Explain->True]

grams

?grams

grams[{{1,2,2,3},{3,6,2,1}}]

{Q,R,ip} = %;

ip[Q,Q]

Q.R

grams[{{1,2,2,3},{3,6,2,1}}, Explain -> True]

grams[{{1,2,2,3},{3,6,2,1}}, Normalized -> False,Explain -> True]

{Q,R,ip} = %;

ip[Q,Q]

Q.R

grams[{{1,2,2,3},{3,6,2,1}},
     InnerProduct -> (Transpose[#1].{{1,1},{1,5}}.#2&),
     Explain -> True
  ]

{Q,R,ip} = %;

ip[Q,Q]

Q.R

invert

?invert

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

invert[{{1,-2,2},{0,-1,1},{2,1,0}}, Explain->True]

invert[{{1,-2,2},{0,-1,1},{2,1,-1}}, Explain->True]

Clear[a];invert[{{1,-2,2},{0,-1,1},{2,1,a}}, Explain->True]

linefit

?linefit

xs =   {0.07, 0.59, 1.33, 1.86, 2.49, 3.12, 3.86, 4.34}

vals =  {0.11, 0.85, 0.77, 2.14, 1.63, 2.27, 3.83, 2.50}

Clear[x];

linefit[xs,vals,x]

linefit[xs,vals,x, Explain -> True]

linefit[xs,vals,x,   Explain -> True, Frame -> True, Background ->
   Eggshell ]

lsq

?lsq

lsq[A = {{2,1,1},{-1,1,2},{1,2,3}}, b = {2,3,1}]

{x,p,e} = %;

e.A

Clear[A,b,x,p,e]

lsq[{{2,1,1},{-1,1,2},{1,2,3}}, {2,3,1}, Explain->True]

null

?null

null[A = {{0,1,-1,0,2},{1,2,-1,1,3},{1,1,0,1,0}}]

nA = %

A.nA

Clear[A,nA]

null[{{0,1,-1,0,2},{1,2,-1,1,3},{1,1,0,1,0}},Explain->True]

permdet

?permdet

permdet[{1,3,4,2}]

permdet[{1,3,4,2}, Explain -> True]

plu

?plu

plu[A = {{1,2,3,4},{2,4,2,1},{-3,1,1,3}}]

{P,L,U,pivcol,sign} = %

L.U

P.A

Clear[P,L,U,pivcol,sign]

plu[{{1,2,3,4},{2,4,2,1},{-3,1,1,3}}, Explain->True]

plu[{{1,2,3,4},{2,4,2,1},{-3,1,1,3}}, Explain->PatternOnly]

projmat

?projmat

projmat[A = {{-1,-1}, {-1,-1},{-1,2}}]

P = %;

(P.{1,2,3} - {1,2,3}).A

Clear[A,P]

projmat[{{-1,-1}, {-1,-1}, {-1,2}}, Explain->True]

randperm

?randperm

randperm[10]

randperm[10, Explain->True]

ref

?ref

ref[{{0,0,1,1,2},{-2,2,0,0,-2},{-2,2,2,1,2},{0,0,-2,-1,-4}}]

ref[{{0,0,1,1,2},{-2,2,0,0,-2},{-2,2,2,1,2},{0,0,-2,-1,-4}},
    Explain->True
 ]

ref[{{0,0,1,1,2},{-2,2,0,0,-2},{-2,2,2,1,2},{0,0,-2,-1,-4}},
    Explain->PatternOnly
 ]

signperm

?signperm

signperm[{3, 1, 4, 5, 2}]

signperm[{3, 1, 4, 5, 2}, Explain->True]

slu

?slu

slu[{{1,2,3},{2,3,2},{-3,1,1}}]

{L,U} = %;

L.U

Clear[L,U]

slu[{{1,2,3},{2,3,2},{-3,1,1}}, Explain->True]

slu[{{1,2,3},{2,3,2},{-3,1,1}}, Explain->PatternOnly]

slu[{{1,2,3},{2,4,2},{-3,1,1}}, Explain->True]

slv

?slv

slv[A={{1,2,3},{2,3,2},{-3,1,1}},{2,1,3}]

A.%

Clear[A]

slv[{{1,2,3},{2,3,2},{-3,1,1}},{2,1,3}, Explain->True]//Timing

slv[{{1,2,3},{2,3,2},{-3,1,1}},{2,1,3}, Explain->PatternOnly]

slv[{{1,2,3},{2,4,2},{-3,1,1}},{2,1,3}, Explain->True]

Clear[a];slv[{{1,2,3},{2,a,2},{-3,1,1}},{2,1,3}, Explain->True]

Simplify[%]

solve

?solve

solve[A = {{1,2,3},{2,4,2},{-3,-6,1}},{4,6,-7}]

A.%

solve[{{1,2,3},{2,4,2},{-3,-6,1}},{4,6,-7}, Explain->True]

solve[{{1,2,3},{2,4,2},{-3,-6,1}},{4,6,-7}, Explain->PatternOnly]

solve[{{1,2,3},{2,4,2},{-3,-6,1}},{4,6,0}, Explain->True]

Clear[a];
 solve[{{1,2,3},{2,4,2},{-3,-6,1}},{4,6,a}, Explain->True]

Consistency requires a = -7

splu

?splu

splu[A = {{1,2,3},{2,4,2},{-3,1,1}}]

{P,L,U,sign} = %;

P.A

L.U

Clear[P,L,U,sign]

splu[{{1,2,3},{2,4,2},{-3,1,1}}, Explain->True]

splu[{{1,2,3},{2,4,2},{-3,1,1}}, Explain->PatternOnly]

splu[{{1,2,3},{2,4,2},{-3,-6,1}}, Explain->True]

Clear[a];splu[{{1,2,3},{2,4,2},{-3,a,1}}, Explain->True]

splv

?splv

splv[A = {{1,2,3},{2,4,2},{-3,1,1}},{2,3,1}]

A.%

Clear[A]

splv[{{1,2,3},{2,4,2},{-3,1,1}},{2,3,1}, Explain->True]

splv[{{1,2,3},{2,4,2},{-3,1,1}},{2,3,1}, Explain->PatternOnly]

splv[{{1,2,3},{2,4,2},{-3,-6,1}},{2,3,1}, Explain->True]

Clear[a];splv[{{1,2,3},{2,4,2},{-3,a,1}},{2,3,1}, Explain->True]