Back to List of Functions

This example uses various linear algebra techniques to demonstrate the following Derive
routines:
identity matrix; append; append columns; row reduce; dimension; column extraction;
determinant; transpose; as well as more than one argument (including text) in the return
statement. As well as producing a solution, the following method also produces the inverse
of the co-efficient matrix.
Given a set of simultaneous linear equations, how do we find the solutions, assuming
they exist? There are many techniques, some more efficient than others, and some more
complex than others. Derive already has numerous in-built functions to solve such
problems. The following routine primarily demonstrates how to append two matrices/vectors
(i.e. join them together), as well as how to extract one or more columns from a matrix
(i.e. producing another vector/matrix).
Without entering into the detailed mathematics, there is a straightforward method of
calculating
a) the inverse of the matrix of co-efficients,
b) the solution vector, and
c) both!
The method involves augmentation, which means 'adding on' or 'appending'
(as in Derive-speak) two vectors or matrices. Suppose we have the following set of linear
simultaneous equations:
| 3x+4y+5z=3 |
| 7x-2y+2z=4 |
| 9x+2y+3z=7 |
In matrix notation, the co-efficients, variables, and solution vectors are given by:



and identity matrix (dimension 3) is given by
i(n):=identity_matrix(n)
So

The general form of the solution is given by
a x = c,
and to use 'augmented' methods to calculate the solution, we append the rhs onto the
matrix a (written as a|c):

We now row reduce
this 3x4 matrix, to
produce an identity matrix in the first 3 columns, and the
solution
in the last column. In Derive, to create this new 3x4 matrix, the
append routine is called. However, the
append function normally only applies to vectors
(one-dimensional matrices), so we need to trick the function into thinking we have two
vectors. We transpose
the original matrix and rhs
vector, then append them, then
transpose the result back again:
a:= append(a`,c`)`
where the 'prime' mark "`" represents
transpose.
If we now row_reduce this 3x4 matrix:
a:= row_reduce(a)
and
simplify:

The first 3 columns represent a 3x3 identity matrix, and the last column is the
solution vector. To extract this solution vector, we can use the
col command:
solution:=a col [4],
which
simplifies to:


Using a similar procedure to calculate the inverse of the co-efficients, we
append the identity matrix onto this matrix. The new
(3x6) matrix is similarly row_reduced, and the
right-hand 'half' of this new matrix is the inverse. So:
a:= append(a`,identity_matrix(3)`)`

and a:= row_reduce(a)
gives

(As a check, by entering
a^(-1) on the entry
line, where a is the original matrix, gives the
same result). To extract the inverse, we can use
inverse:= a col [4,...,6]
where [4,...,6] represents an
inclusive range of columns, remembering to use just three ellipses:

So, maintaining the original
and

and calling the function gauss2(a,c)
gives
