comparison toolbox/gearm.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 = gearm(n, i, j)
2 %GEARM Gear matrix.
3 % A = GEARM(N,I,J) is the N-by-N matrix with ones on the sub- and
4 % super-diagonals, SIGN(I) in the (1,ABS(I)) position, SIGN(J)
5 % in the (N,N+1-ABS(J)) position, and zeros everywhere else.
6 % Defaults: I = N, j = -N.
7 % All eigenvalues are of the form 2*COS(a) and the eigenvectors
8 % are of the form [SIN(w+a), SIN(w+2a), ..., SIN(w+Na)].
9 % The values of a and w are given in the reference below.
10 % A can have double and triple eigenvalues and can be defective.
11 % GEARM(N) is singular.
12
13 % (GEAR is a Simulink function, hence GEARM for Gear matrix.)
14 % Reference:
15 % C.W. Gear, A simple set of test matrices for eigenvalue programs,
16 % Math. Comp., 23 (1969), pp. 119-125.
17
18 if nargin == 1, i = n; j = -n; end
19
20 if ~(i~=0 & abs(i)<=n & j~=0 & abs(j)<=n)
21 error('Invalid I and J parameters')
22 end
23
24 A = diag(ones(n-1,1),-1) + diag(ones(n-1,1),1);
25 A(1, abs(i)) = sign(i);
26 A(n, n+1-abs(j)) = sign(j);