The following module in Forth computes the "similar" matrix, in
tridiagonal form, for a real square matrix, i.e. it tridiagonalizes the
input matrix using a series of similarity transformations. ...
I don't know its relative efficiency in comparison with those routines
(e.g. tred2 from EISPACK), but it's a starting point.
I translated the EISPACK subroutine tred1 from Fortran to Forth, and
verified for one matrix case that both Fortran and Forth versions gave
the same output.
On 6/8/22 09:38, Krishna Myneni wrote:[..]
The above Forth module, together with the already translated tred1.4th,
and using FSL arrays and matrices, provide a way to compute eigenvalues
of real symmetric matrices in Forth. Thus, finding eigenvalues for one
major category of matrices may now be handled simply in Forth, without
the need for external library interfaces.
On Saturday, June 11, 2022 at 6:05:56 PM UTC+2, Krishna Myneni wrote:
On 6/8/22 09:38, Krishna Myneni wrote:[..]
The above Forth module, together with the already translated tred1.4th,
and using FSL arrays and matrices, provide a way to compute eigenvalues
of real symmetric matrices in Forth. Thus, finding eigenvalues for one
major category of matrices may now be handled simply in Forth, without
the need for external library interfaces.
In 2006, I sent Skip Carter eigenvals.frt (358 lines) for the FSL.
It has been under review for 16 years by now :--)
: .about
CR ." HOUSEHOLDER-REDUCE ( a{{ d{ e{ -- ) must be real and symmetric"
CR ." TRIDIAGONAL-QL-IMPLICIT ( d{ e{ -- bool ) must be real and symmetric"
CR ." TQLI-EIGENVECTORS ( z{{ d{ e{ -- flag ) must be real and symmetric"
CR ." EXTREME-EVS ( s{{ -- ) ( F: -- ev_max ev_min ) any matrix"
CR ." LARGEST-EV ( s{{ -- ) ( F: -- ev ) any matrix"
CR ." SMALLEST-EV ( s{{ -- ) ( F: -- ev ) any matrix"
CR ." SYMMETRIC? ( x{{ -- TRUE=yes ) " ;
In any case, my goal here is to have a set of Forth modules which map
one to one to the well-tested and well-documented EISPACK routines, for
my own use.
The Forth words will be demonstrated to have identical
behavior to their Fortran subroutine counterparts, and thus will be
traceable to EISPACK. The comprehensive book, Matrix Eigensystem
Routines -- Eispack Guide, by B. T. Smith, J. M. Boyle, et al., Springer 2013, appears to be still in print. Other guides also exist on the internet.
https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/extras/imtql1.4th
The above Forth module, together with the already translated tred1.4th,
and using FSL arrays and matrices, provide a way to compute eigenvalues
of real symmetric matrices in Forth. Thus, finding eigenvalues for one
major category of matrices may now be handled simply in Forth, without
the need for external library interfaces.
On Monday, June 13, 2022 at 4:00:40 PM UTC+2, Krishna Myneni wrote:
On 6/11/22 11:05, Krishna Myneni wrote:[..]
https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/extras/imtql1.4th...
The above Forth module, together with the already translated tred1.4th,...
and using FSL arrays and matrices, provide a way to compute eigenvalues
of real symmetric matrices in Forth. Thus, finding eigenvalues for one
major category of matrices may now be handled simply in Forth, without
the need for external library interfaces.
An example of using the two modules, tred1 and imtql1, to solve for the
eigenvalues of a real symmetric matrix, using the 4x4 matrix from the
original post, is given below.
\ 4 x 4 real symmetric matrix example[..]
4 4 FLOAT MATRIX A{{
4.0e0 1.0e0 -2.0e0 2.0e0
1.0e0 2.0e0 0.0e0 1.0e0
-2.0e0 0.0e0 3.0e0 -2.0e0
2.0e0 1.0e0 -2.0e0 -1.0e0
4 4 A{{ }}fput
-2.19752 1.08436 2.26853 6.84462 ok
The eigenvalues of the matrix, sorted from smallest to largest, are
shown in the last line of the output. One may use R or matlab to verify
the eigenvalues.
FORTH> a{{ =eigv ok
[2]FORTH> swap }}print ( complex eigenvalues on diagonal )
( 6.844621e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 )
( 0.000000e+0000 0.000000e+0000 ) ( -2.197517e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 )
( 0.000000e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 ) ( 1.084364e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 )
( 0.000000e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 ) ( 0.000000e+0000 0.000000e+0000 ) ( 2.268531e+0000 0.000000e+0000 ) ok
[1]FORTH> }}print ( complex eigenvectors in columns )
( 7.180460e-0001 0.000000e+0000 ) ( 1.767052e-0001 0.000000e+0000 ) ( -6.422600e-0001 0.000000e+0000 ) ( -2.017111e-0001 0.000000e+0000 )
( 2.211530e-0001 0.000000e+0000 ) ( 1.781005e-0001 0.000000e+0000 ) ( 5.441878e-0001 0.000000e+0000 ) ( -7.894499e-0001 0.000000e+0000 )
( -5.573514e-0001 0.000000e+0000 ) ( -2.876680e-0001 0.000000e+0000 ) ( -5.202219e-0001 0.000000e+0000 ) ( -5.796342e-0001 0.000000e+0000 )
( 3.533565e-0001 0.000000e+0000 ) ( -9.242849e-0001 0.000000e+0000 ) ( 1.439823e-0001 0.000000e+0000 ) ( -1.028100e-0002 0.000000e+0000 ) ok
The eigenvalues appear to be correct.
On 6/11/22 11:05, Krishna Myneni wrote:[..]
https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/extras/imtql1.4th
...
The above Forth module, together with the already translated tred1.4th,
and using FSL arrays and matrices, provide a way to compute eigenvalues
of real symmetric matrices in Forth. Thus, finding eigenvalues for one major category of matrices may now be handled simply in Forth, without
the need for external library interfaces.
...
An example of using the two modules, tred1 and imtql1, to solve for the eigenvalues of a real symmetric matrix, using the 4x4 matrix from the original post, is given below.
\ 4 x 4 real symmetric matrix example[..]
4 4 FLOAT MATRIX A{{
4.0e0 1.0e0 -2.0e0 2.0e0
1.0e0 2.0e0 0.0e0 1.0e0
-2.0e0 0.0e0 3.0e0 -2.0e0
2.0e0 1.0e0 -2.0e0 -1.0e0
4 4 A{{ }}fput
-2.19752 1.08436 2.26853 6.84462 ok
The eigenvalues of the matrix, sorted from smallest to largest, are
shown in the last line of the output. One may use R or matlab to verify
the eigenvalues.
On 6/13/22 12:30, Marcel Hendrix wrote:[..]
The eigenvalues of the matrix, sorted from smallest to largest, are
[..]shown in the last line of the output. One may use R or matlab to verify
the eigenvalues.
FORTH> a{{ =eigv ok
[..][1]FORTH> }}print ( complex eigenvectors in columns )
The eigenvalues are real, as they should be for a real symmetric matrix.
If the matrix is real, but not symmetric, then there is the possibility/likelihood of complex eigenvalues.
On Monday, June 13, 2022 at 7:43:10 PM UTC+2, Krishna Myneni wrote:
On 6/13/22 12:30, Marcel Hendrix wrote:[..]
The eigenvalues of the matrix, sorted from smallest to largest, are
Sorting the eigenvalues (and eigenvectors) is a nice touch.
[..]shown in the last line of the output. One may use R or matlab to verify >>>> the eigenvalues.
FORTH> a{{ =eigv ok
[..][1]FORTH> }}print ( complex eigenvectors in columns )
The eigenvalues are real, as they should be for a real symmetric matrix.
If the matrix is real, but not symmetric, then there is the
possibility/likelihood of complex eigenvalues.
For electrical engineering problems the matrices are normally non-symmetric (eigenvalues almost always complex).
On 6/8/22 09:38, Krishna Myneni wrote:
...
I translated the EISPACK subroutine tred1 from Fortran to Forth, and...
verified for one matrix case that both Fortran and Forth versions gave
the same output.
I completed translation of the EISPACK subroutine IMTQL1 from Fortran to Forth. The word IMTQL1 computes the eigenvalues of a real symmetric tridiagonal matrix. ...
Of course, IMTQL1 can only provide eigenvalues. For solving the complete eigenvalue problem for this category of matrices, we also need the eigenvectors. For this we need Forth implementations of EISPACK's
tred2() and imtql2() as well.
I translated the EISPACK subroutine tred1 from Fortran to Forth, ...
My Forth translation of tred1 may be found at
https://github.com/mynenik/kForth-64/tree/master/forth-src/fsl/extras
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 43:28:42 |
Calls: | 6,709 |
Calls today: | 2 |
Files: | 12,243 |
Messages: | 5,354,021 |