(*:Mathematica:: V2.0 *) (*:Context: "LinearAlgebra`MatrixOps`" *) (*:Title: Elementary Matrix Operations *) (*:Author: Dennis M. Snow, Department of Mathematics *) (*:Summary: Provides simple manipulations of matrices for Math 226 *) (*:History: Created January 23, 1992 *) BeginPackage["LinearAlgebra`MatrixOps`"]; JoinColumns::usage= "JoinColumns[A,B,...] combines the matrices (and/or vectors) A,B,... by columns into a new matrix." E1::usage = "E1[A,i,j] switches the ith and jth rows of the matrix A" E2::usage = "E2[A,i,d] multiplies the ith row of A by the scalar d" E3::usage = "E3[A,i,d,j] adds d times the jth row of A to the ith row of A" Cofactors::usage = "Cofactors[A] returns the cofactor matrix of A" Begin["`Private`"] JoinColumns[A_?MatrixQ,B_?MatrixQ] := Transpose[ Join[Transpose[A], Transpose[B]]] JoinColumns[A_?MatrixQ,B_?VectorQ] := Transpose[ Join[Transpose[A], {B}]] JoinColumns[A_?VectorQ,B_?MatrixQ] := Transpose[ Join[{A}, Transpose[B]]] JoinColumns[A_?VectorQ,B_?VectorQ] := Transpose[ Join[{A}, {B}]] JoinColumns[A_, B_, C___] := JoinColumns[ JoinColumns[A,B], C] E1[A_List,i_,j_] := Block[{m = A, r = A[[i]]}, m[[i]] = A[[j]]; m[[j]] = r; m ] E2[A_List,i_,d_] := Block[{m = A}, m[[i]] = d A[[i]]; m ] E3[A_List,i_,d_,j_] := Block[{m = A}, m[[i]] = A[[i]] + d A[[j]]; m ] Cofactors[A_?MatrixQ] := Block[{n = Length[A], m}, m = Minors[A,n-1]; Table[(-1)^(i+j)m[[n-i+1,n-j+1]], {i,1,n}, {j,1,n}] ] End[] EndPackage[]