Mercurial > matrix-functions
comparison toolbox/pascal.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 P = pascal(n, k) | |
2 %PASCAL Pascal matrix. | |
3 % P = PASCAL(N) is the Pascal matrix of order N: a symmetric positive | |
4 % definite matrix with integer entries taken from Pascal's | |
5 % triangle. | |
6 % The Pascal matrix is totally positive and its inverse has | |
7 % integer entries. Its eigenvalues occur in reciprocal pairs. | |
8 % COND(P) is approximately 16^N/(N*PI) for large N. | |
9 % PASCAL(N,1) is the lower triangular Cholesky factor (up to signs | |
10 % of columns) of the Pascal matrix. It is involutary (is its own | |
11 % inverse). | |
12 % PASCAL(N,2) is a transposed and permuted version of PASCAL(N,1) | |
13 % which is a cube root of the identity. | |
14 | |
15 % References: | |
16 % R. Brawer and M. Pirovino, The linear algebra of the Pascal matrix, | |
17 % Linear Algebra and Appl., 174 (1992), pp. 13-23 (this paper | |
18 % gives a factorization of L = PASCAL(N,1) and a formula for the | |
19 % elements of L^k). | |
20 % N.J. Higham, Accuracy and Stability of Numerical Algorithms, | |
21 % Society for Industrial and Applied Mathematics, Philadelphia, PA, | |
22 % USA, 1996; sec. 26.4. | |
23 % S. Karlin, Total Positivity, Volume 1, Stanford University Press, | |
24 % 1968. (Page 137: shows i+j-1 choose j is TP (i,j=0,1,...). | |
25 % PASCAL(N) is a submatrix of this matrix.) | |
26 % M. Newman and J. Todd, The evaluation of matrix inversion programs, | |
27 % J. Soc. Indust. Appl. Math., 6(4):466--476, 1958. | |
28 % H. Rutishauser, On test matrices, Programmation en Mathematiques | |
29 % Numeriques, Editions Centre Nat. Recherche Sci., Paris, 165, | |
30 % 1966, pp. 349-365. (Gives an integral formula for the | |
31 % elements of PASCAL(N).) | |
32 % J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, | |
33 % Birkhauser, Basel, and Academic Press, New York, 1977, p. 172. | |
34 % H.W. Turnbull, The Theory of Determinants, Matrices, and Invariants, | |
35 % Blackie, London and Glasgow, 1929. (PASCAL(N,2) on page 332.) | |
36 | |
37 if nargin == 1, k = 0; end | |
38 | |
39 P = diag( (-1).^[0:n-1] ); | |
40 P(:, 1) = ones(n,1); | |
41 | |
42 % Generate the Pascal Cholesky factor (up to signs). | |
43 for j=2:n-1 | |
44 for i=j+1:n | |
45 P(i,j) = P(i-1,j) - P(i-1,j-1); | |
46 end | |
47 end | |
48 | |
49 if k == 0 | |
50 | |
51 P = P*P'; | |
52 | |
53 elseif k == 2 | |
54 | |
55 P = rot90(P,3); | |
56 if n/2 == round(n/2), P = -P; end | |
57 | |
58 end |