home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 22
/
CD_ASCQ_22_0695.iso
/
win
/
educ
/
rtkspad
/
matfctns.sp_
/
matfctns
(
.txt
)
Wrap
Microsoft Windows Help File Content
|
1995-05-08
|
27KB
|
406 lines
R-Tek Scratchpad
Version 1.00
TSPadDatad
TPictured
TCommentTextd
TLogFontd
Times New Roman
densed BT
Matrix Functions
nnnnnnnnnnnnnnnn]
TCommentTextd
The matrix operators were described in the example file "basics". This file describes
the built-in matrix functions. Context sensitive help is available for built-in functions
with Ctrl+F1 when the caret is positioned on a function name within an expression.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
imat(3)
TExpressiond
zmat(2,3)
TExpressiond
onesvec(4)
TExpressiond
V:rmat(6,1,5)
TExpressiond
A:rmat(6,6,-5)
TExpressiond
submat(A,2,3,4,5)
TExpressiond
subvec(V,2,4)
TCommentTextd
rmatex0, rmatex01, rmatexint, rmatexs, rmatexs0, rmatexs01, rmatexsint
These rmatex? functions exists just like the rndex? numeric functions to exclude specific
matrix element values. rmatexs? type functions exclude singular square matrices.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
Ctrl+m produces a display matrix, whose values you fill in yourself. You can change the
size of a display matrix by Alt+m on an active display matrix element. You can also change
the matrix element alignment by changing the expression's numeric format, either
globally or individually.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
A common way of producing an initialized matrix is to create a zmat and then calculate the
matrix elements in a matloop. Use the matrix subscript grouping chars [ and ] to identify a
particular matrix element.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
m:zmat(3,4)
TMatLoopd
TExpressiond
m[i,j]
TCommentTextd
The matloop is equivalent to two whiles and take on values
that correspond to all the matrix elements. i and j are commonly
used as subscript identifiers but you are free to choose any names
you wish.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnn]
TExpressiond
m[i,j]:10*i+j
TEndMatLoopd
TExpressiond
THardPageBreakd
TExpressiond
randomize(39)
TCommentTextd
seed the random number generator to produce the same sequence of
random numbers each time you run the program.n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
exclude singular because we
want the inverse later2
nnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
m:rmatexs(3,3,4)
TExpressiond
sum(m)
TCommentTextd
sum of elements
nnnnnnnnnnnnnnn]
TExpressiond
mean(m)
TExpressiond
max(m)
TCommentTextd
maximum
nnnnnnn]
TExpressiond
var(m)
TCommentTextd
variance
nnnnnnnn]
TExpressiond
min(m)
TCommentTextd
minimum
nnnnnnn]
TExpressiond
stddev(m)
TCommentTextd
standard deviation
nnnnnnnnnnnnnnnnnn]
TExpressiond
tr(m)
TCommentTextd
trace - the sum of the diagonal
elements of m 0+3+05
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
use the column extraction grouping chars Ctrl+[ and Ctrl+]:
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
TCommentTextd
use the row extraction grouping chars Alt+[ and Alt+]5
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
TExpressiond
reverse(m)
TCommentTextd
reverses the order of the rows of m#
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
reverses the order of the elements of a vector.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
reverse(v)
TCommentTextd
sorts the elements of a vector
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
sort(v)
TCommentTextd
sorts the columns of m based on the values in the nth row9
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
csort(m,1)
TCommentTextd
sorts the rows of m based on the values in the nth column9
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
rsort(m,2)
THardPageBreakd
TExpressiond
TCommentTextd
refresh our memory of m
nnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
minor(m,3,1)
TCommentTextd
the minor of m is the determinant of the submatrix formed
by eliminating the ith row and the jth column of ml
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
minor(m,1,3)
TExpressiond
adj(m)
TCommentTextd
the adjoint matrix is one whose elements are the
transposed cofactors of its original elements, ie
the signed minors of order n-1.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
The adjoint matrix is related to the matrix inverse by Cramers rule.D
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
TExpressiond
1/{m}*adj(m)
TExpressiond
TCommentTextd
scalar multiplication - note that division by a scalar
is not allowed (although you can get away with
multiplying by a fraction)
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
The rank of a matrix is the number of linearly independent rows of m, which must be
less than or equal to the number of columns of m. If the rank of a square matrix m is
less than the number of rows, the matrix is singular (does not possess an inverse). The
determinant of such a matrix is zero.)
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
does possess an inverse
nnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
rank(m)
TExpressiond
s:M000300031@2@3@2@1@5@2@4@6@
TCommentTextd
does not possess an inverse
nnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
rank(s)
TExpressiond
echelon(s)
TCommentTextd
echelon(m) converts m to echelon form through elementary
row operations. If the matrix has an inverse, the echelon form
of the matrix is the identity matrix. The number of non-zero
rows of the echelon form is the rank of m.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
THardPageBreakd
TCommentTextd
echtrans(m) is the matrix product of all the elementary
row operations that convert m to echelon form. If the
matrix has an inverse, echtrans(m) produces the inverse.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
echtrans(s)
TExpressiond
TExpressiond
b:M000300012@-1@3@
TCommentTextd
The simple way of solving a matrix equation of the form A * x=b is:C
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
which is verified by:
nnnnnnnnnnnnnnnnnnnnn]
TExpressiond
x:A^-1*b
TExpressiond
TCommentTextd
but for the case where the matrix is singular, the inverse does not exist.
The system of equations may have either no solution, in which case we
say the equations are inconsistant, or the equations may have an infinite
number of related solutions.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
Consider A, an m x n matrix of rank r and that A * x = b.9
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
If b is all zeros, this is called the homogeneous case. In this case, if r = n,
there is the trivial solution (where x is all zeros) only. If r<n, there exist
non-trivial solutions.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
If b is not all zeros, then the equations may be either consistant or inconsistant.
the equations are consistant if there is no row in the echelon form of the augmented matrx
that has its first nonzero element in the final column.
if r=n and the equations are consistant, the solution is unique.
if r<n and the equations are consistant, the solution is not unique.l
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
b:M00040001-2@-1@5@10@
TExpressiond
A:M000400042@0@4@0@3@1@4@0@1@0@2@1@0@2@-4@1@,
TExpressiond
augment:AUb
TExpressiond
echelon(augment)
TCommentTextd
no row with first nonzero element in
final column means that the equations
are consistantZ
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnn]
THardPageBreakd
TCommentTextd
rank less than number of columns of A implies multiple solutions@
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
rank(A)
TExpressiond
p:psolve(A,b)
TExpressiond
h:hsolve(A)
TCommentTextd
psolve(m, b) gives a particular solution.)
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
hsolve(m) gives a homogenous solution%
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
The general solution to this type of matrix equation is a linear combination of the
particular solution plus any scalar multiple of the homogeneous solution.
This general solution is really an infinite number of related solutions
for example:
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnn]
TCommentTextd
k is any arbitrary constant (make it whatever you like)7
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
TExpressiond
x:p+k*h
TCommentTextd
demonstrate that x is a solution of A * x=b.,
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
TCommentTextd
compare to b above
nnnnnnnnnnnnnnnnnn]
TCommentTextd
Next, look at Gram-Schmidt orthonormalization. The function orthonorm(m) produces
a matrix whose columns provide an orthonormal basis for the vectors that are the columns
of the original non-singular matrix.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
TExpressiond
gs:orthonorm(m)
TExpressiond
m2:gs
TExpressiond
m3:gs
TExpressiond
m1:gs
TExpressiond
TExpressiond
TExpressiond
TExpressiond
TExpressiond
TExpressiond
TExpressiond
TExpressiond
TExpressiond
THardPageBreakd
TExpressiond
m1xm1
TExpressiond
m2xm1
TExpressiond
m3xm1
TExpressiond
m1xm2
TExpressiond
m2xm2
TExpressiond
m3xm2
TExpressiond
m1xm3
TExpressiond
m2xm3
TExpressiond
m3xm3
TCommentTextd
Another useful function of the scratchpad is pivot which performs Gauss-Jordan elimination on
the indicated row,column element.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
TCommentTextd
We will calculate the inverse of m as an example of using pivot. Note that if you do this yourself,
you will need to run the program after each new choice of pivot so that you can view the result,
which will lead in turn to the next choice of a pivot element. (Another example of using pivot is
in the linear programming example file "lp_multi".)]
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
A:mUimat(3)
TCommentTextd
First augment m with the identity matrix. We
solve for the inverse by using elementary row
operations to create an identity matrix on the left.
The right columns will then form the inverse of
the original matrix.
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnn]
TExpressiond
TCommentTextd
Exchange rows 1 and 2
nnnnnnnnnnnnnnnnnnnnn]
TExpressiond
A:pivot(A,1,1)
TExpressiond
temp:pivot(A,2,2)
THardPageBreakd
TCommentTextd
Note that pivot(A, 2, 2) above was equivalent to the following elementary row operations:Y
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TCommentTextd
recall:
nnnnnnn]
TExpressiond
TCommentTextd
Instead of pivot(A, 2, 2) do:
nnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
:1/2*A
TExpressiond
TExpressiond
TCommentTextd
compare to:
nnnnnnnnnnn]
TExpressiond
TExpressiond
TCommentTextd
Left side of A is identity matrix,
so we have found the inverse of mE
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnznnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
TExpressiond
A:pivot(A,3,3)
TCommentTextd
Compare to:
nnnnnnnnnnn]
TExpressiond
submat(A,1,4,3,6)
TExpressiond
TPrinterDimensionsd
TSPadInitDatad
TLogFontd
Times New Roman
densed BT
TLogFontd
Arial
TLogFontd
Arial
TLogFontd
Symbol
TLogFontd
Symbol
TNumberFormatDatad
TGraphSetupDatad
TPageSetupDatad
R-Tek Scratchpad Example File MATFCTNS