Mercurial > matrix-functions
comparison toolbox/makejcf.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 A = makejcf(n, e, m, X) | |
2 %MAKEJCF A matrix with given Jordan canonical form. | |
3 % MAKEJCF(N, E, M) is a matrix having the Jordan canonical form | |
4 % whose i'th Jordan block is of dimension M(i) with eigenvalue E(i), | |
5 % and where N = SUM(M). | |
6 % Defaults: E = 1:N, M = ONES(SIZE(E)) with M(1) so that SUM(M) = N. | |
7 % The matrix is constructed by applying a random similarity | |
8 % transformation to the Jordan form. | |
9 % Alternatively, the matrix used in the similarity transformation | |
10 % can be specified as a fifth parameter. | |
11 % In particular, MAKEJCF(N, E, M, EYE(N)) returns the Jordan form | |
12 % itself. | |
13 % NB: The JCF is very sensitive to rounding errors. | |
14 | |
15 if nargin < 2, e = 1:n; end | |
16 if nargin < 3, m = ones(size(e)); m(1) = m(1) + n - sum(m); end | |
17 | |
18 if any( size(e(:)) ~= size(m(:)) ) | |
19 error('Parameters E and M must be of same dimension.') | |
20 end | |
21 | |
22 if sum(m) ~= n, error('Block dimensions must add up to N.'), end | |
23 | |
24 A = zeros(n); | |
25 j = 1; | |
26 for i=1:max(size(m)) | |
27 if m(i) > 1 | |
28 Jb = jordbloc(m(i),e(i)); | |
29 else | |
30 Jb = e(i); % JORDBLOC fails in n = 1 case. | |
31 end | |
32 A(j:j+m(i)-1,j:j+m(i)-1) = Jb; | |
33 j = j + m(i); | |
34 end | |
35 | |
36 if nargin < 4 | |
37 X = randn(n); | |
38 end | |
39 A = X\A*X; |