Dec 102017
Improved Matrix OPs from Byte, APR 89. | |||
---|---|---|---|
File Name | File Size | Zip Size | Zip Type |
M16.DAT | 6001 | 904 | deflated |
M16X.DAT | 6376 | 911 | deflated |
M3.DAT | 30 | 27 | deflated |
M32.DAT | 23778 | 3709 | deflated |
M32X.DAT | 24520 | 3715 | deflated |
M3X.DAT | 39 | 25 | deflated |
M4.DAT | 49 | 37 | deflated |
M4X.DAT | 61 | 34 | deflated |
M8.DAT | 217 | 118 | deflated |
M8X.DAT | 1701 | 351 | deflated |
MATRIX2.DOC | 4229 | 1758 | deflated |
MATRIX2.EXE | 24128 | 15090 | deflated |
MATRIX2.PAS | 10513 | 2751 | deflated |
Download File MATRIX2.ZIP Here
Contents of the MATRIX2.DOC file
To print this file enter TYPE MATRIX2.DOC > PRN from DOS.
MATRIX2
MATRIX2 is basically a matrix inversion program to which the
equation solutions have been added. It is configured for up to
32 equations.
Rather than using Gaussian elimination (triangularizing the
input matrix), the program iterates a matrix inversion using
Newton's method. This is desribed in [1].
The significant point is that even though no inverse can be
found for an equation set which includes dependent (or the same)
equations, a solution is found which satisfies the input
equations. (This may be obvious but it surprised me.)
Examples are included on the disk, where they are named mn.dat
where n is an integer. The files mnx.dat have the first equation
repeated, and do not give an invertible matrix. Even so the
program finds a valid solution. Thus if your problem requires
any solution to 3 equations in 4 variables, repeat one of the
three equations, and run the program. I would like to be able to
say something about this solution, but I'm not a mathemetician.
I suspect, based on the few examples herein, that the program
finds the smallest (vector magnitude?) valid solution.
No proof is offerd (or claimed) that the program always finds a
solution which checks. In fact this is clearly impossible for an
input which includes the same equation with different input
solutions, that is parallel lines. In this case the program
apparently finds solutions which solve the independent equations
and averages the input solutions of the parelles lines.
As a check, the output solution vector is plugged back into the
input equations to see if the input solution vector is correctly
computed.
The program monitors a solution error which is the largest
element in the difference matrix I-M*MI where MI is the computed
inverse of M, and I is the identity matrix. For large (over 8)
matrices which apparently invert, this value is typically on the
order of ten to the minus 14 - 16. For small invertible
matrices, it is 0. For matrices mnx.dat which clearly don't
invert, the error is in the range 0.1 - 0.9. The program
includes a warning when the error is greater than 1e-8. This
should caution to continue the iteration, and, if the solution
has converged, recognize that is is not unique.
The program allows input from the keyboard or a disk file. In
the disk file mode it also records the answer. Use the NUL file
to avoid this output.
The program does 20 iterations plus it continues iterating as
long as the error is decreasing. For all but the m32x.dat this
sufficient for convergence. There is a continue option which
allows additional iterations in blocks of 5 plus the tests for
decreasing error. The number of iterations and the solution
error are monitored on the screen.
The program is compiled in Turbo Pascal v5.0. It uses double
precision (8 byte) variables. My machine has an 8087 numerical
processor, however the code for 8087 emulation should be
included; I just don't have any way to try it. With the 8087 the
32 equation matrix takes about 7 minutes on my IBM PC.
I have included the Pascal source code. Any user is welcome to
use and modify the program except for commercial purposes. I
claim all rights to the program, and I disclaim all
responsiblity for the results of using the program whether or
not it gives correct answers. You use the program at your own
risk. I do sincerely thank you for your interest.
William M. Hutchinson
11470 E. Calle Aurora
Tucson, Az. 85748
602-290-8187
[1] 'The Inversion of Large Matrices', Thomas E. Phipps, BYTE
(magazine), April, 1986.
MATRIX2
MATRIX2 is basically a matrix inversion program to which the
equation solutions have been added. It is configured for up to
32 equations.
Rather than using Gaussian elimination (triangularizing the
input matrix), the program iterates a matrix inversion using
Newton's method. This is desribed in [1].
The significant point is that even though no inverse can be
found for an equation set which includes dependent (or the same)
equations, a solution is found which satisfies the input
equations. (This may be obvious but it surprised me.)
Examples are included on the disk, where they are named mn.dat
where n is an integer. The files mnx.dat have the first equation
repeated, and do not give an invertible matrix. Even so the
program finds a valid solution. Thus if your problem requires
any solution to 3 equations in 4 variables, repeat one of the
three equations, and run the program. I would like to be able to
say something about this solution, but I'm not a mathemetician.
I suspect, based on the few examples herein, that the program
finds the smallest (vector magnitude?) valid solution.
No proof is offerd (or claimed) that the program always finds a
solution which checks. In fact this is clearly impossible for an
input which includes the same equation with different input
solutions, that is parallel lines. In this case the program
apparently finds solutions which solve the independent equations
and averages the input solutions of the parelles lines.
As a check, the output solution vector is plugged back into the
input equations to see if the input solution vector is correctly
computed.
The program monitors a solution error which is the largest
element in the difference matrix I-M*MI where MI is the computed
inverse of M, and I is the identity matrix. For large (over 8)
matrices which apparently invert, this value is typically on the
order of ten to the minus 14 - 16. For small invertible
matrices, it is 0. For matrices mnx.dat which clearly don't
invert, the error is in the range 0.1 - 0.9. The program
includes a warning when the error is greater than 1e-8. This
should caution to continue the iteration, and, if the solution
has converged, recognize that is is not unique.
The program allows input from the keyboard or a disk file. In
the disk file mode it also records the answer. Use the NUL file
to avoid this output.
The program does 20 iterations plus it continues iterating as
long as the error is decreasing. For all but the m32x.dat this
sufficient for convergence. There is a continue option which
allows additional iterations in blocks of 5 plus the tests for
decreasing error. The number of iterations and the solution
error are monitored on the screen.
The program is compiled in Turbo Pascal v5.0. It uses double
precision (8 byte) variables. My machine has an 8087 numerical
processor, however the code for 8087 emulation should be
included; I just don't have any way to try it. With the 8087 the
32 equation matrix takes about 7 minutes on my IBM PC.
I have included the Pascal source code. Any user is welcome to
use and modify the program except for commercial purposes. I
claim all rights to the program, and I disclaim all
responsiblity for the results of using the program whether or
not it gives correct answers. You use the program at your own
risk. I do sincerely thank you for your interest.
William M. Hutchinson
11470 E. Calle Aurora
Tucson, Az. 85748
602-290-8187
[1] 'The Inversion of Large Matrices', Thomas E. Phipps, BYTE
(magazine), April, 1986.
December 10, 2017
Add comments