John E. Howland
Department of Computer Science
Trinity University
715 Stadium Drive
San Antonio, Texas 78212-7200
Voice: (210) 999-7364
Fax: (210) 999-7477
E-mail: jhowland@Trinity.Edu
Web: http://www.cs.trinity.edu/~jhowland/
Subject Areas: Linear Systems.
Keywords: Modeling, J Programming Language, Solving Linear Systems of Equations.
In these notes, we consider the problem of solving linear systems of equations. A linear system of equations in unknowns, may be written as:
Let be a matrix having rows and 1 column represent the unknowns, a matrix having rows and 1 column representing the right-hand sides of equations (1), and an by matrix of coefficients of each of the equations (1),
Then, given the J definition of matrix product
mp =: +/ . *
we can rewrite the equations (1) as the matrix equation:
This linear system of equations can be solved by computing the inverse matrix, of and multiplying both sides of equation (3) on the left (matrix multiplication is not commutative) by
The inverse matrix, exists when and only when the determinant of (discussed in Section 2) is non-zero. Simplifying equation (4) we have
(5) |
Where is the by identitiy matrix ( 1's down the main diagonal, 0 elsewhere). The identity matrix satisfies the equation
for any by square matrix .
The J monad %.
computes the inverse matrix. Consider the following
example:
(7) |
The coefficient matrix for this system is
(8) |
In J we solve this system in the following manner. We first define
mp
and setup the coefficient matrix.
mp =: +/ . * [a =: 3 3 $ 2 3 _4 _4 2 5 3 _2 3 2 3 _4 _4 2 5 3 _2 3 [b =: 12 3 5 12 3 5
Next check the determinant of the coefficient matrix to insure that the system has a solution (the determinant must be non-zero).
det =: -/ . * det a 105
The matrix inverse, %.
, is used to compute the solution of the
system of 3 equations in 3 unknowns.
(%.a) mp b 2.89524 3.88571 1.3619
Finally we check our answer by:
a mp (%.a) mp b 12 3 5
A linear system of equations in unknowns, as shown in equations (1), has a solution if and only if the determinant of the corresponding matrix of coefficients (2) is non-zero. Given an by matrix of real numbers such as (2), we define the determinant of recursively as the real number determined as:
(9) |
The minor of an element of an by matrix shown in (2), is the by matrix which is obtained by deleting row and column of A.
As an example, consider the following J matrix:
[a =: 3 3 $ 2 3 _4 _4 2 5 3 _2 3 2 3 _4 _4 2 5 3 _2 3 minors=: }."1 @ (1&([\.)) minors a 2 5 _2 3 3 _4 _2 3 3 _4 2 5
We can see that minors
computes the minors (first row to last) of the
first column of a matrix. Using the definition of a determinant, we have
Using the J definition for minors, we now compute the minors of each of the
by matrices in minors a
.
minors "2 minors a 3 5 3 _4 5 _4
Hence, we can compute each of the determinants in equation (10).
Hence . We can use the J primitive for determinant to check our answer.
det =: -/ . * det a 105