Mercurial > hg > octave-nkf
annotate scripts/special-matrix/pascal.m @ 9051:1bf0ce0930be
Grammar check TexInfo in all .m files
Cleanup documentation sources to follow a few consistent rules.
Spellcheck was NOT done. (but will be in another changeset)
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 27 Mar 2009 22:31:03 -0700 |
parents | 853f96e8008f |
children | 2e35cfcf6a6a |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1999, 2006, 2007 Peter Ekberg |
5827 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5827 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5827 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} pascal (@var{n}, @var{t}) | |
21 ## | |
22 ## Return the Pascal matrix of order @var{n} if @code{@var{t} = 0}. | |
23 ## @var{t} defaults to 0. Return lower triangular Cholesky factor of | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
24 ## the Pascal matrix if @code{@var{t} = 1}. This matrix is its own |
5827 | 25 ## inverse, that is @code{pascal (@var{n}, 1) ^ 2 == eye (@var{n})}. |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
26 ## If @code{@var{t} = 2}, return a transposed and permuted version of |
5827 | 27 ## @code{pascal (@var{n}, 1)}, which is the cube-root of the identity |
9041
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
28 ## matrix. That is @code{pascal (@var{n}, 2) ^ 3 == eye (@var{n})}. |
5827 | 29 ## |
30 ## @seealso{hankel, vander, sylvester_matrix, hilb, invhilb, toeplitz | |
31 ## hadamard, wilkinson, compan, rosser} | |
32 ## @end deftypefn | |
33 | |
34 ## Author: Peter Ekberg | |
35 ## (peda) | |
36 | |
37 function retval = pascal (n, t) | |
38 | |
39 if (nargin > 2) || (nargin == 0) | |
40 print_usage (); | |
41 endif | |
42 | |
43 if (nargin == 1) | |
44 t = 0; | |
45 endif | |
46 | |
47 if (! is_scalar (n) || ! is_scalar (t)) | |
48 error ("pascal: expecting scalar arguments, found something else"); | |
49 endif | |
50 | |
51 retval = diag ((-1).^[0:n-1]); | |
52 retval(:,1) = ones (n, 1); | |
53 | |
54 for j = 2:n-1 | |
55 for i = j+1:n | |
56 retval(i,j) = retval(i-1,j) - retval(i-1,j-1); | |
57 endfor | |
58 endfor | |
59 | |
60 if (t == 0) | |
61 retval = retval*retval'; | |
62 elseif (t == 2) | |
63 retval = retval'; | |
64 retval = retval(n:-1:1,:); | |
65 retval(:,n) = -retval(:,n); | |
66 retval(n,:) = -retval(n,:); | |
67 if (rem(n,2) != 1) | |
68 retval = -retval; | |
69 endif | |
70 endif | |
71 | |
72 endfunction |