Mercurial > matrix-functions
comparison toolbox/krylov.m @ 2:c124219d7bfa draft
Re-add the 1995 toolbox after noticing the statement in the ~higham/mctoolbox/ webpage.
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Thu, 07 May 2015 18:36:24 +0200 |
parents | 8f23314345f4 |
children |
comparison
equal
deleted
inserted
replaced
1:e471a92d17be | 2:c124219d7bfa |
---|---|
1 function B = krylov(A, x, j) | |
2 %KRYLOV Krylov matrix. | |
3 % KRYLOV(A, x, j) is the Krylov matrix | |
4 % [x, Ax, A^2x, ..., A^(j-1)x], | |
5 % where A is an n-by-n matrix and x is an n-vector. | |
6 % Defaults: x = ONES(n,1), j = n. | |
7 % KRYLOV(n) is the same as KRYLOV(RANDN(n)). | |
8 | |
9 % Reference: | |
10 % G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, | |
11 % Johns Hopkins University Press, Baltimore, Maryland, 1989, p. 369. | |
12 | |
13 [n, n] = size(A); | |
14 | |
15 if n == 1 % Handle special case A = scalar. | |
16 n = A; | |
17 A = randn(n); | |
18 end | |
19 | |
20 if nargin < 3, j = n; end | |
21 if nargin < 2, x = ones(n,1); end | |
22 | |
23 | |
24 B = ones(n,j); | |
25 B(:,1) = x(:); | |
26 for i=2:j | |
27 B(:,i) = A*B(:,i-1); | |
28 end |