7.8 Inner Product Space Operations
The following functions treat matrices as vectors in an inner product space. It often makes most sense to use these vector-space functions only for row matrices and column matrices, which are essentially vectors as we normally think of them. There are exceptions, however, such as the fact that the Frobenius or Euclidean norm (implemented by matrix-2norm) can be used to measure error between matrices in a way that meets certain reasonable criteria (specifically, it is submultiplicative).
See Operator Norms and Comparing Matrices for similar functions (e.g. norms and angles) defined by considering matrices as operators between inner product spaces consisting of column matrices.
procedure
(matrix-1norm M) → Nonnegative-Real
M : (Matrix Number)
procedure
(matrix-2norm M) → Nonnegative-Real
M : (Matrix Number)
procedure
M : (Matrix Number)
procedure
(matrix-norm M [p]) → Nonnegative-Real
M : (Matrix Number) p : Real = 2
The L1 norm is also known under the names Manhattan or taxicab norm. The L1 norm of a matrix is the sum of magnitudes of the entries in the matrix.
The L2 norm is also known under the names Euclidean or Frobenius norm. The L2 norm of a matrix is the square root of the sum of squares of magnitudes of the entries in the matrix.
The L∞ norm is also known as the maximum or infinity norm. The L∞ norm computes the maximum magnitude of the entries in the matrix.
For p >= 1, matrix-norm computes the Lp norm: the pth root of the sum of all entry magnitudes to the pth power.
> (matrix-1norm (col-matrix [1 2])) 3
> (matrix-2norm (col-matrix [1 2])) 2.23606797749979
> (matrix-inf-norm (col-matrix [1 2])) 2
> (matrix-norm (col-matrix [1 2]) 3) 2.080083823051904
> (matrix-norm (col-matrix [1 2]) +inf.0) 2
procedure
(matrix-dot M) → Nonnegative-Real
M : (Matrix Number) (matrix-dot M N) → Number M : (Matrix Number) N : (Matrix Number)
> (matrix-dot (col-matrix [1 2]) (col-matrix [3 4])) 11
> (+ (* 1 3) (* 2 4)) 11
(/ (matrix-dot M N) (* (matrix-2norm M) (matrix-2norm N)))
> (define M (col-matrix [1 0])) > (define N (col-matrix [0 1])) > (matrix-cos-angle M N) 0
> (matrix-cos-angle M (matrix+ M N)) 0.7071067811865475
> (require (only-in math/base radians->degrees)) > (define M (col-matrix [1 0])) > (define N (col-matrix [0 1])) > (radians->degrees (matrix-angle M N)) 90.0
> (radians->degrees (matrix-angle M (matrix+ M N))) 45.00000000000001
procedure
(matrix-normalize M [p fail]) → (U F (Matrix Number))
M : (Matrix Number) p : Real = 2 fail : (-> F) = (λ () (error ...))
> (matrix-normalize (col-matrix [1 1])) - : (Array Real)
(array #[#[0.7071067811865475] #[0.7071067811865475]])
> (matrix-normalize (col-matrix [1 1]) 1) - : (Array Real)
(array #[#[1/2] #[1/2]])
> (matrix-normalize (col-matrix [1 1]) +inf.0) - : (Array Real)
(array #[#[1] #[1]])
procedure
(matrix-normalize-rows M [p fail]) → (Matrix Number)
M : (Matrix Number) p : Real = 2 fail : (-> F) = (λ () (error ...))
procedure
(matrix-normalize-cols M [p fail]) → (Matrix Number)
M : (Matrix Number) p : Real = 2 fail : (-> F) = (λ () (error ...))
> (matrix-normalize-rows (matrix [[1 2] [2 4]])) - : (Array Real)
(array
#[#[0.4472135954999579 0.8944271909999159]
#[0.4472135954999579 0.8944271909999159]])
> (matrix-normalize-cols (matrix [[1 2] [2 4]])) - : (Array Real)
(array
#[#[0.4472135954999579 0.4472135954999579]
#[0.8944271909999159 0.8944271909999159]])
procedure
(matrix-rows-orthogonal? M [eps]) → Boolean
M : (Matrix Number) eps : Real = (* 10 epsilon.0)
procedure
(matrix-cols-orthogonal? M [eps]) → Boolean
M : (Matrix Number) eps : Real = (* 10 epsilon.0)
> (matrix-rows-orthogonal? (matrix [[1 1] [-1 1]])) #t
> (matrix-cols-orthogonal? (matrix [[1 1] [-1 1]])) #t