home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Krylov matrix.
-
- // Syntax: K = krylov ( A , x , j )
-
- // Description:
-
- // K is the Krylov matrix
- // [x, Ax, A^2x, ..., A^(j-1)x],
- // where A is an n-by-n matrix and x is an n-vector.
-
- // Defaults: x = ONES(n,1), j = n.
-
- // krylov(n) is the same as krylov(rand(n,n)).
-
- // Reference:
- // G.H. Golub and C.F. Van Loan, Matrix Computations, second edition,
- // Johns Hopkins University Press, Baltimore, Maryland, 1989, p. 369.
-
- // This file is a translation of krylov.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- //-------------------------------------------------------------------//
-
- krylov = function ( A , x, j )
- {
- local (A, x, j)
-
- n = A.nr;
-
- if (n == 1) // Handle special case A = scalar.
- {
- n = A;
- rand("normal", 0, 1);
- A = rand(n,n);
- }
-
- if (!exist (j)) { j = n; }
- if (!exist (x)) { x = ones(n,1); }
-
- B = ones(n,j);
- B[;1] = x[:];
- for (i in 2:j)
- {
- B[;i] = A*B[;i-1];
- }
-
- return B;
- };
-