Mercurial > hg > octave-nkf
annotate scripts/special-matrix/pascal.m @ 10791:3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
interpreter/doccheck: New directory for spelling/grammar scripts.
interpreter/doccheck/README: Instructions for using scripts.
interpreter/doccheck/spellcheck: Script to spellcheck a Texinfo file.
interpreter/doccheck/aspell.conf: GNU Aspell configuration file for
Octave documentation.
interpreter/doccheck/aspell-octave.en.pws: Private Aspell dictionary.
interpreter/doccheck/add_to_aspell_dict: Script to add new
Octave-specific words to
private Aspell dictionary.
interpreter/octave.texi: New @nospell macro which forces Aspell
to ignore the word marked by the macro.
interpreter/mk_doc_cache.m: Skip new @nospell macro when building
doc_cache.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 17 Jul 2010 19:53:01 -0700 |
parents | 923c7cb7f13f |
children | dcde7c5a1d29 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1999, 2006, 2007 Peter Ekberg |
9094
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
2 ## Copyright (C) 2009 VZLU Prague |
5827 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
5827 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5827 | 19 |
20 ## -*- texinfo -*- | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
21 ## @deftypefn {Function File} {} pascal (@var{n}) |
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
22 ## @deftypefnx {Function File} {} pascal (@var{n}, @var{t}) |
5827 | 23 ## |
24 ## Return the Pascal matrix of order @var{n} if @code{@var{t} = 0}. | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
25 ## @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
|
26 ## the Pascal matrix if @code{@var{t} = 1}. This matrix is its own |
5827 | 27 ## inverse, that is @code{pascal (@var{n}, 1) ^ 2 == eye (@var{n})}. |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9096
diff
changeset
|
28 ## If @code{@var{t} = -1}, return its absolute value. This is the |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
29 ## standard Pascal triangle as a lower-triangular matrix. |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
30 ## If @code{@var{t} = 2}, return a transposed and permuted version of |
5827 | 31 ## @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
|
32 ## matrix. That is @code{pascal (@var{n}, 2) ^ 3 == eye (@var{n})}. |
5827 | 33 ## |
34 ## @seealso{hankel, vander, sylvester_matrix, hilb, invhilb, toeplitz | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
9209
diff
changeset
|
35 ## hadamard, wilkinson, compan, rosser} |
5827 | 36 ## @end deftypefn |
37 | |
38 ## Author: Peter Ekberg | |
39 ## (peda) | |
40 | |
41 function retval = pascal (n, t) | |
42 | |
43 if (nargin > 2) || (nargin == 0) | |
44 print_usage (); | |
45 endif | |
46 | |
47 if (nargin == 1) | |
48 t = 0; | |
49 endif | |
50 | |
9094
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
51 if (! isscalar (n) || ! isscalar (t)) |
5827 | 52 error ("pascal: expecting scalar arguments, found something else"); |
53 endif | |
54 | |
9094
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
55 retval = zeros (n); |
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
56 retval(:,1) = 1; |
5827 | 57 |
9094
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
58 if (t == -1) |
9096 | 59 for j = 2:n |
9094
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
60 retval(j:n,j) = cumsum (retval (j-1:n-1,j-1)); |
5827 | 61 endfor |
9094
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
62 else |
9096 | 63 for j = 2:n |
9094
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
64 retval(j:n,j) = -cumsum (retval (j-1:n-1,j-1)); |
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
65 endfor |
2e35cfcf6a6a
fix, optimize & extend pascal
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
66 endif |
5827 | 67 |
68 if (t == 0) | |
69 retval = retval*retval'; | |
70 elseif (t == 2) | |
71 retval = retval'; | |
72 retval = retval(n:-1:1,:); | |
73 retval(:,n) = -retval(:,n); | |
74 retval(n,:) = -retval(n,:); | |
75 if (rem(n,2) != 1) | |
76 retval = -retval; | |
77 endif | |
78 endif | |
79 | |
80 endfunction |