comparison matrixcomp/makejcf.m @ 0:8f23314345f4 draft

Create local repository for matrix toolboxes. Step #0 done.
author Antonio Pino Robles <data.script93@gmail.com>
date Wed, 06 May 2015 14:56:53 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8f23314345f4
1 function A = makejcf(n, e, m, X)
2 %MAKEJCF A matrix with specified 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 length(e) ~= length(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 = gallery('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;