Mercurial > hg > octave-lyh
annotate doc/interpreter/tips.txi @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 17be601bc783 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14116
diff
changeset
|
1 @c Copyright (C) 1996-2012 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
9032
349616d9c38e
Cleanup top-level documentation menu in octave.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
19 @node Tips and Standards |
3294 | 20 @appendix Tips and Standards |
21 @cindex tips | |
22 @cindex standards of coding style | |
23 @cindex coding standards | |
24 | |
25 This chapter describes no additional features of Octave. Instead it | |
26 gives advice on making effective use of the features described in the | |
27 previous chapters. | |
28 | |
29 @menu | |
30 * Style Tips:: Writing clean and robust programs. | |
31 * Comment Tips:: Conventions for writing comments. | |
32 * Function Headers:: Standard headers for functions. | |
6574 | 33 * Documentation Tips:: Writing readable documentation strings. |
3294 | 34 @end menu |
35 | |
4167 | 36 @node Style Tips |
3294 | 37 @section Writing Clean Octave Programs |
38 | |
39 Here are some tips for avoiding common errors in writing Octave code | |
40 intended for widespread use: | |
41 | |
42 @itemize @bullet | |
43 @item | |
44 Since all global variables share the same name space, and all functions | |
45 share another name space, you should choose a short word to distinguish | |
46 your program from other Octave programs. Then take care to begin the | |
47 names of all global variables, constants, and functions with the chosen | |
48 prefix. This helps avoid name conflicts. | |
49 | |
50 If you write a function that you think ought to be added to Octave under | |
51 a certain name, such as @code{fiddle_matrix}, don't call it by that name | |
52 in your program. Call it @code{mylib_fiddle_matrix} in your program, | |
5041 | 53 and send mail to @email{maintainers@@octave.org} suggesting that it |
3294 | 54 be added to Octave. If and when it is, the name can be changed easily |
55 enough. | |
56 | |
57 If one prefix is insufficient, your package may use two or three | |
58 alternative common prefixes, so long as they make sense. | |
59 | |
60 Separate the prefix from the rest of the symbol name with an underscore | |
61 @samp{_}. This will be consistent with Octave itself and with most | |
62 Octave programs. | |
63 | |
64 @item | |
65 When you encounter an error condition, call the function @code{error} | |
66 (or @code{usage}). The @code{error} and @code{usage} functions do not | |
67 return. | |
68 @xref{Errors}. | |
69 | |
70 @item | |
71 Please put a copyright notice on the file if you give copies to anyone. | |
72 Use the same lines that appear at the top of the function files | |
73 distributed with Octave. If you have not signed papers to assign the | |
74 copyright to anyone else, then place your name in the copyright notice. | |
75 @end itemize | |
76 | |
77 | |
4167 | 78 @node Comment Tips |
3294 | 79 @section Tips on Writing Comments |
80 | |
81 Here are the conventions to follow when writing comments. | |
82 | |
83 @table @samp | |
84 @item # | |
85 Comments that start with a single sharp-sign, @samp{#}, should all be | |
86 aligned to the same column on the right of the source code. Such | |
87 comments usually explain how the code on the same line does its job. In | |
88 the Emacs mode for Octave, the @kbd{M-;} (@code{indent-for-comment}) | |
89 command automatically inserts such a @samp{#} in the right place, or | |
90 aligns such a comment if it is already present. | |
91 | |
92 @item ## | |
7345 | 93 Comments that start with a double sharp-sign, @samp{##}, should be aligned to |
3294 | 94 the same level of indentation as the code. Such comments usually |
95 describe the purpose of the following lines or the state of the program | |
96 at that point. | |
97 @end table | |
98 | |
99 @noindent | |
100 The indentation commands of the Octave mode in Emacs, such as @kbd{M-;} | |
101 (@code{indent-for-comment}) and @kbd{TAB} (@code{octave-indent-line}) | |
102 automatically indent comments according to these conventions, | |
103 depending on the number of semicolons. @xref{Comments,, | |
104 Manipulating Comments, emacs, The GNU Emacs Manual}. | |
105 | |
4167 | 106 @node Function Headers |
3294 | 107 @section Conventional Headers for Octave Functions |
108 @cindex header comments | |
109 | |
110 Octave has conventions for using special comments in function files | |
111 to give information such as who wrote them. This section explains these | |
112 conventions. | |
113 | |
114 The top of the file should contain a copyright notice, followed by a | |
115 block of comments that can be used as the help text for the function. | |
116 Here is an example: | |
117 | |
118 @example | |
6778 | 119 ## Copyright (C) 1996, 1997, 2007 John W. Eaton |
3294 | 120 ## |
121 ## This file is part of Octave. | |
122 ## | |
123 ## Octave is free software; you can redistribute it and/or | |
124 ## modify it under the terms of the GNU General Public | |
125 ## License as published by the Free Software Foundation; | |
7081 | 126 ## either version 3 of the License, or (at your option) any |
127 ## later version. | |
3294 | 128 ## |
129 ## Octave is distributed in the hope that it will be useful, | |
130 ## but WITHOUT ANY WARRANTY; without even the implied | |
131 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
132 ## PURPOSE. See the GNU General Public License for more | |
133 ## details. | |
134 ## | |
135 ## You should have received a copy of the GNU General Public | |
136 ## License along with Octave; see the file COPYING. If not, | |
7016 | 137 ## see <http://www.gnu.org/licenses/>. |
3294 | 138 |
139 ## usage: [IN, OUT, PID] = popen2 (COMMAND, ARGS) | |
140 ## | |
141 ## Start a subprocess with two-way communication. COMMAND | |
142 ## specifies the name of the command to start. ARGS is an | |
143 ## array of strings containing options for COMMAND. IN and | |
144 ## OUT are the file ids of the input and streams for the | |
145 ## subprocess, and PID is the process id of the subprocess, | |
146 ## or -1 if COMMAND could not be executed. | |
147 ## | |
148 ## Example: | |
149 ## | |
150 ## [in, out, pid] = popen2 ("sort", "-nr"); | |
151 ## fputs (in, "these\nare\nsome\nstrings\n"); | |
152 ## fclose (in); | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7345
diff
changeset
|
153 ## while (ischar (s = fgets (out))) |
3294 | 154 ## fputs (stdout, s); |
155 ## endwhile | |
156 ## fclose (out); | |
157 @end example | |
158 | |
159 Octave uses the first block of comments in a function file that do not | |
160 appear to be a copyright notice as the help text for the file. For | |
161 Octave to recognize the first comment block as a copyright notice, it | |
6530 | 162 must start with the word `Copyright' after stripping the leading |
163 comment characters. | |
3294 | 164 |
165 After the copyright notice and help text come several @dfn{header | |
166 comment} lines, each beginning with @samp{## @var{header-name}:}. For | |
167 example, | |
168 | |
169 @example | |
170 @group | |
171 ## Author: jwe | |
172 ## Keywords: subprocesses input-output | |
173 ## Maintainer: jwe | |
174 @end group | |
175 @end example | |
176 | |
177 Here is a table of the conventional possibilities for @var{header-name}: | |
178 | |
179 @table @samp | |
180 @item Author | |
181 This line states the name and net address of at least the principal | |
182 author of the library. | |
183 | |
6670 | 184 @example |
9322 | 185 ## Author: John W. Eaton <jwe@@octave.org> |
6670 | 186 @end example |
3294 | 187 |
188 @item Maintainer | |
189 This line should contain a single name/address as in the Author line, or | |
190 an address only, or the string @samp{jwe}. If there is no maintainer | |
191 line, the person(s) in the Author field are presumed to be the | |
192 maintainers. The example above is mildly bogus because the maintainer | |
193 line is redundant. | |
194 | |
195 The idea behind the @samp{Author} and @samp{Maintainer} lines is to make | |
196 possible a function to ``send mail to the maintainer'' without | |
197 having to mine the name out by hand. | |
198 | |
199 Be sure to surround the network address with @samp{<@dots{}>} if | |
200 you include the person's full name as well as the network address. | |
201 | |
202 @item Created | |
203 This optional line gives the original creation date of the | |
204 file. For historical interest only. | |
205 | |
206 @item Version | |
207 If you wish to record version numbers for the individual Octave program, | |
208 put them in this line. | |
209 | |
210 @item Adapted-By | |
211 In this header line, place the name of the person who adapted the | |
212 library for installation (to make it fit the style conventions, for | |
213 example). | |
214 | |
215 @item Keywords | |
216 This line lists keywords. Eventually, it will be used by an apropos | |
217 command to allow people will find your package when they're looking for | |
218 things by topic area. To separate the keywords, you can use spaces, | |
219 commas, or both. | |
220 @end table | |
221 | |
222 Just about every Octave function ought to have the @samp{Author} and | |
223 @samp{Keywords} header comment lines. Use the others if they are | |
224 appropriate. You can also put in header lines with other header | |
225 names---they have no standard meanings, so they can't do any harm. | |
6574 | 226 |
227 @node Documentation Tips | |
228 @section Tips for Documentation Strings | |
229 | |
230 As noted above, documentation is typically in a commented header block | |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
231 on an Octave function following the copyright statement. The help string |
7001 | 232 shown above is an unformatted string and will be displayed as is by |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
233 Octave. Here are some tips for the writing of documentation strings. |
6574 | 234 |
235 @itemize @bullet | |
236 @item | |
237 Every command, function, or variable intended for users to know about | |
238 should have a documentation string. | |
239 | |
240 @item | |
241 An internal variable or subroutine of an Octave program might as well have | |
242 a documentation string. | |
243 | |
244 @item | |
245 The first line of the documentation string should consist of one or two | |
246 complete sentences that stand on their own as a summary. | |
247 | |
248 The documentation string can have additional lines that expand on the | |
249 details of how to use the function or variable. The additional lines | |
250 should also be made up of complete sentences. | |
251 | |
252 @item | |
253 For consistency, phrase the verb in the first sentence of a | |
254 documentation string as an infinitive with ``to'' omitted. For | |
255 instance, use ``Return the frob of A and B.'' in preference to ``Returns | |
256 the frob of A and B@.'' Usually it looks good to do likewise for the | |
257 rest of the first paragraph. Subsequent paragraphs usually look better | |
258 if they have proper subjects. | |
259 | |
260 @item | |
261 Write documentation strings in the active voice, not the passive, and in | |
262 the present tense, not the future. For instance, use ``Return a list | |
263 containing A and B.'' instead of ``A list containing A and B will be | |
264 returned.'' | |
265 | |
266 @item | |
267 Avoid using the word ``cause'' (or its equivalents) unnecessarily. | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
268 Instead of, ``Cause Octave to display text in boldface,'' just write |
6574 | 269 ``Display text in boldface.'' |
270 | |
271 @item | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
272 Use two spaces between the period marking the end of a sentence and the |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
273 word which opens the next sentence. This convention has no effect for |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
274 typeset formats like @TeX{}, but improves the readability of the documentation |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
275 in fixed-width environments such as the Info reader. |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
276 |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
277 @item |
6574 | 278 Do not start or end a documentation string with whitespace. |
279 | |
280 @item | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
281 Format the documentation string so that it fits within an 80-column screen. |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
282 It is a good idea for most lines to be no wider than 60 characters. |
6574 | 283 |
284 However, rather than simply filling the entire documentation string, you | |
285 can make it much more readable by choosing line breaks with care. | |
286 Use blank lines between topics if the documentation string is long. | |
287 | |
288 @item | |
289 @strong{Do not} indent subsequent lines of a documentation string so | |
290 that the text is lined up in the source code with the text of the first | |
291 line. This looks nice in the source code, but looks bizarre when users | |
292 view the documentation. Remember that the indentation before the | |
293 starting double-quote is not part of the string! | |
294 | |
295 @item | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
296 When choosing variable names try to adhere to the following guidelines. |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
297 |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
298 @table @asis |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
299 @item vectors : |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
300 x,y,z,t,w |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
301 |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
302 @item matrices : |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
303 A,B,M |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
304 |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
305 @item strings : |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
306 @nospell{str},s |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
307 |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
308 @item filenames : |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
309 @nospell{fname} |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
310 |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
311 @item cells,@nospell{cellstrs} : |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
312 c,@nospell{cstr} |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
313 @end table |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
314 |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
315 @item |
6574 | 316 The documentation string for a variable that is a yes-or-no flag should |
317 start with words such as ``Nonzero means@dots{}'', to make it clear that | |
318 all nonzero values are equivalent and indicate explicitly what zero and | |
319 nonzero mean. | |
320 | |
321 @item | |
322 When a function's documentation string mentions the value of an argument | |
323 of the function, use the argument name in capital letters as if it were | |
324 a name for that value. Thus, the documentation string of the operator | |
325 @code{/} refers to its second argument as @samp{DIVISOR}, because the | |
326 actual argument name is @code{divisor}. | |
327 | |
328 Also use all caps for meta-syntactic variables, such as when you show | |
329 the decomposition of a list or vector into subunits, some of which may | |
330 vary. | |
331 @end itemize | |
332 | |
333 Octave also allows extensive formatting of the help string of functions | |
334 using Texinfo. The effect on the online documentation is relatively | |
335 small, but makes the help string of functions conform to the help of | |
336 Octave's own functions. However, the effect on the appearance of printed | |
337 or online documentation will be greatly improved. | |
338 | |
339 The fundamental building block of Texinfo documentation strings is the | |
340 Texinfo-macro @code{@@deftypefn}, which takes three arguments: The class | |
341 the function is in, its output arguments, and the function's | |
342 signature. Typical classes for functions include @code{Function File} | |
343 for standard Octave functions, and @code{Loadable Function} for | |
344 dynamically linked functions. A skeletal Texinfo documentation string | |
345 therefore looks like this | |
346 | |
347 @example | |
348 @group | |
349 -*- texinfo -*- | |
16790
d21bf69e49b2
doc: Update some spacing in the Tips & Standards chapter.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
350 @@deftypefn @{Function File@} @{@@var@{ret@} =@} fn (@dots{}) |
6574 | 351 @@cindex index term |
7081 | 352 Help text in Texinfo format. Code samples should be marked |
353 like @@code@{sample of code@} and variables should be marked | |
354 as @@var@{variable@}. | |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16790
diff
changeset
|
355 @@seealso@{fn2, fn3@} |
6574 | 356 @@end deftypefn |
357 @end group | |
358 @end example | |
359 | |
360 This help string must be commented in user functions, or in the help | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9080
diff
changeset
|
361 string of the @w{@code{DEFUN_DLD}} macro for dynamically loadable |
6574 | 362 functions. The important aspects of the documentation string are |
363 | |
364 @table @asis | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10284
diff
changeset
|
365 @item -*- @nospell{texinfo} -*- |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7768
diff
changeset
|
366 This string signals Octave that the following text is in Texinfo format, |
6574 | 367 and should be the first part of any help string in Texinfo format. |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10812
diff
changeset
|
368 |
16790
d21bf69e49b2
doc: Update some spacing in the Tips & Standards chapter.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
369 @item @@deftypefn @{class@} @dots{} @@end deftypefn |
6574 | 370 The entire help string should be enclosed within the block defined by |
371 deftypefn. | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10812
diff
changeset
|
372 |
6574 | 373 @item @@cindex index term |
374 This generates an index entry, and can be useful when the function is | |
375 included as part of a larger piece of documentation. It is ignored | |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
376 within Octave's help viewer. Only one index term may appear per line |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
377 but multiple @@cindex lines are valid if the function should be |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
378 filed under different terms. |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10812
diff
changeset
|
379 |
6574 | 380 @item @@var@{variable@} |
381 All variables should be marked with this macro. The markup of variables | |
382 is then changed appropriately for display. | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10812
diff
changeset
|
383 |
6574 | 384 @item @@code@{sample of code@} |
385 All samples of code should be marked with this macro for the same | |
386 reasons as the @@var macro. | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10812
diff
changeset
|
387 |
17298
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17297
diff
changeset
|
388 @item @nospell{@@qcode@{"sample_code"@}} |
17be601bc783
doc: Periodic spellchecking of documentation.
Rik <rik@octave.org>
parents:
17297
diff
changeset
|
389 @itemx @nospell{@@qcode@{'sample_code'@}} |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16790
diff
changeset
|
390 All samples of code which are quoted should use this more specialized macro. |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16790
diff
changeset
|
391 This happens frequently when discussing graphics properties such as "position" |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16790
diff
changeset
|
392 or options such as "on"/"off". |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16790
diff
changeset
|
393 |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16790
diff
changeset
|
394 @item @@seealso@{function2, function3@} |
6574 | 395 This is a comma separated list of function names that allows cross |
396 referencing from one function documentation string to another. | |
397 @end table | |
398 | |
399 Texinfo format has been designed to generate output for online viewing | |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
400 with text terminals as well as generating high-quality printed output. |
6574 | 401 To these ends, Texinfo has commands which control the diversion of parts |
402 of the document into a particular output processor. Three formats are | |
16790
d21bf69e49b2
doc: Update some spacing in the Tips & Standards chapter.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
403 of importance: info, HTML, and @TeX{}. These are selected with |
6574 | 404 |
405 @example | |
406 @group | |
407 @@ifinfo | |
408 Text area for info only | |
409 @@end ifinfo | |
410 @end group | |
411 @end example | |
412 | |
413 @example | |
414 @group | |
415 @@ifhtml | |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
416 Text area for HTML only |
6574 | 417 @@end ifhtml |
418 @end group | |
419 @end example | |
420 | |
421 @example | |
422 @group | |
423 @@tex | |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
424 Text area for TeX only |
6574 | 425 @@end tex |
426 @end group | |
427 @end example | |
428 | |
10791
3140cb7a05a1
Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents:
10284
diff
changeset
|
429 Note that often @TeX{} output can be used in HTML documents and so often |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
430 the @code{@@ifhtml} blocks are unnecessary. If no specific output |
6574 | 431 processor is chosen, by default, the text goes into all output |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
432 processors. It is usual to have the above blocks in pairs to allow the |
6574 | 433 same information to be conveyed in all output formats, but with a |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
434 different markup. Currently, most Octave documentation only makes a |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
435 distinction between @TeX{} and all other formats. Therefore, the |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
436 following construct is seen repeatedly. |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
437 |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
438 @example |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
439 @group |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
440 @@tex |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
441 text for TeX only |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
442 @@end tex |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
443 @@ifnottex |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
444 text for info, HTML, plaintext |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
445 @@end ifnottex |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
446 @end group |
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
447 @end example |
6574 | 448 |
449 Another important feature of Texinfo that is often used in Octave help | |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
450 strings is the @code{@@example} environment. An example of its use is |
6574 | 451 |
452 @example | |
453 @group | |
454 @@example | |
455 @@group | |
456 @@code@{2 * 2@} | |
457 @@result@{@} 4 | |
458 @@end group | |
459 @@end example | |
460 @end group | |
461 @end example | |
462 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
463 @noindent |
6574 | 464 which produces |
465 | |
466 @example | |
467 @group | |
468 @code{2 * 2} | |
469 @result{} 4 | |
470 @end group | |
471 @end example | |
472 | |
473 The @code{@@group} block prevents the example from being split across a | |
474 page boundary, while the @code{@@result@{@}} macro produces a right | |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
475 arrow signifying the result of a command. If your example is larger than |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16790
diff
changeset
|
476 20 lines it is better @emph{NOT} to use grouping so that a reasonable page |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16790
diff
changeset
|
477 boundary can be calculated. |
6574 | 478 |
8828 | 479 In many cases a function has multiple ways in which it can be called, |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
480 and the @code{@@deftypefnx} macro can be used to give alternatives. For |
6574 | 481 example |
482 | |
483 @example | |
484 @group | |
485 -*- texinfo -*- | |
16790
d21bf69e49b2
doc: Update some spacing in the Tips & Standards chapter.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
486 @@deftypefn @{Function File@} @{@@var@{a@} =@} fn (@@var@{x@}, @dots{}) |
d21bf69e49b2
doc: Update some spacing in the Tips & Standards chapter.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
487 @@deftypefnx @{Function File@} @{@@var@{a@} =@} fn (@@var@{y@}, @dots{}) |
6574 | 488 Help text in Texinfo format. |
489 @@end deftypefn | |
490 @end group | |
491 @end example | |
492 | |
493 Many complete examples of Texinfo documentation can be taken from the | |
9080
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
494 help strings for the Octave functions themselves. A relatively complete |
ec41eabf4499
Cleanup documentation files dynamic.texi, testfun.texi, tips.texi
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
495 example of which is the @code{nchoosek} function. The Texinfo |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
496 documentation string for @code{nchoosek} is |
6574 | 497 |
498 @example | |
499 -*- texinfo -*- | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
500 @@deftypefn @{Function File@} @{@@var@{c@} =@} nchoosek (@@var@{n@}, @@var@{k@}) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
501 @@deftypefnx @{Function File@} @{@@var@{c@} =@} nchoosek (@@var@{set@}, @@var@{k@}) |
6574 | 502 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
503 Compute the binomial coefficient or all combinations of a set of items. |
6574 | 504 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
505 If @@var@{n@} is a scalar then calculate the binomial coefficient |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
506 of @@var@{n@} and @@var@{k@} which is defined as |
6574 | 507 @@tex |
508 $$ | |
509 @{n \choose k@} = @{n (n-1) (n-2) \cdots (n-k+1) \over k!@} | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
510 = @{n! \over k! (n-k)!@} |
6574 | 511 $$ |
512 @@end tex | |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
513 @@ifnottex |
6574 | 514 |
515 @@example | |
516 @@group | |
517 / \ | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
518 | n | n (n-1) (n-2) @@dots@{@} (n-k+1) n! |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
519 | | = ------------------------- = --------- |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
520 | k | k! k! (n-k)! |
6574 | 521 \ / |
522 @@end group | |
523 @@end example | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
524 |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
525 @@end ifnottex |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
526 @@noindent |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
527 This is the number of combinations of @@var@{n@} items taken in groups of |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
528 size @@var@{k@}. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
529 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
530 If the first argument is a vector, @@var@{set@}, then generate all |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
531 combinations of the elements of @@var@{set@}, taken @@var@{k@} at a time, with |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
532 one row per combination. The result @@var@{c@} has @@var@{k@} columns and |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
533 @@w@{@@code@{nchoosek (length (@@var@{set@}), @@var@{k@})@}@} rows. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
534 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
535 For example: |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
536 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
537 How many ways can three items be grouped into pairs? |
6574 | 538 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
539 @@example |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
540 @@group |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
541 nchoosek (3, 2) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
542 @@result@{@} 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
543 @@end group |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
544 @@end example |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
545 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
546 What are the possible pairs? |
6574 | 547 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
548 @@example |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
549 @@group |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
550 nchoosek (1:3, 2) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
551 @@result@{@} 1 2 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
552 1 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
553 2 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
554 @@end group |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
555 @@end example |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
556 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
557 @@code@{nchoosek@} works only for non-negative, integer arguments. Use |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
558 @@code@{bincoeff@} for non-integer and negative scalar arguments, or for |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
559 computing many binomial coefficients at once with vector inputs |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
560 for @@var@{n@} or @@var@{k@}. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
561 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
562 @@seealso@{bincoeff, perms@} |
6574 | 563 @@end deftypefn |
564 @end example | |
17297
4d7f95eb8bfe
doc: Miscellaneous small tweaks to documentation for consistency.
Rik <rik@octave.org>
parents:
17289
diff
changeset
|
565 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
566 @noindent |
6574 | 567 which demonstrates most of the concepts discussed above. |
568 @iftex | |
569 This documentation string renders as | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
570 @c Note: use the actual output of info below, rather than try and |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
571 @c reproduce it here to prevent it looking different from how it would |
6574 | 572 @c appear with info. |
17297
4d7f95eb8bfe
doc: Miscellaneous small tweaks to documentation for consistency.
Rik <rik@octave.org>
parents:
17289
diff
changeset
|
573 |
6574 | 574 @example |
575 -- Function File: C = nchoosek (N, K) | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
576 -- Function File: C = nchoosek (SET, K) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
577 Compute the binomial coefficient or all combinations of a set of |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
578 items. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
579 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
580 If N is a scalar then calculate the binomial coefficient of N and |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
581 K which is defined as |
6574 | 582 |
583 / \ | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
584 | n | n (n-1) (n-2) ... (n-k+1) n! |
7081 | 585 | | = ------------------------- = --------- |
586 | k | k! k! (n-k)! | |
6574 | 587 \ / |
588 | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
589 This is the number of combinations of N items taken in groups of |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
590 size K. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
591 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
592 If the first argument is a vector, SET, then generate all |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
593 combinations of the elements of SET, taken K at a time, with one |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
594 row per combination. The result C has K columns and |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
595 `nchoosek (length (SET), K)' rows. |
6574 | 596 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
597 For example: |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
598 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
599 How many ways can three items be grouped into pairs? |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
600 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
601 nchoosek (3, 2) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
602 => 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
603 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
604 What are the possible pairs? |
6574 | 605 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
606 nchoosek (1:3, 2) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
607 => 1 2 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
608 1 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
609 2 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
610 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
611 `nchoosek' works only for non-negative, integer arguments. Use |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
612 `bincoeff' for non-integer and negative scalar arguments, or for |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
613 computing many binomial coefficients at once with vector inputs |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
614 for N or K. |
6574 | 615 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
616 See also: bincoeff, perms |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
617 @end example |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
618 @noindent |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
619 using info, whereas in a printed documentation using @TeX{} it will |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
620 appear as |
6574 | 621 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
622 @deftypefn {Function File} {@var{c} =} nchoosek (@var{n}, @var{k}) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
623 @deftypefnx {Function File} {@var{c} =} nchoosek (@var{set}, @var{k}) |
6574 | 624 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
625 Compute the binomial coefficient or all combinations of a set of items. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
626 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
627 If @var{n} is a scalar then calculate the binomial coefficient |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
628 of @var{n} and @var{k} which is defined as |
6574 | 629 |
630 @tex | |
631 $$ | |
632 {n \choose k} = {n (n-1) (n-2) \cdots (n-k+1) \over k!} | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
633 = {n! \over k! (n-k)!} |
6574 | 634 $$ |
635 @end tex | |
636 | |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
637 @noindent |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
638 This is the number of combinations of @var{n} items taken in groups of |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
639 size @var{k}. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
640 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
641 If the first argument is a vector, @var{set}, then generate all |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
642 combinations of the elements of @var{set}, taken @var{k} at a time, with |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
643 one row per combination. The result @var{c} has @var{k} columns and |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
644 @w{@code{nchoosek (length (@var{set}), @var{k})}} rows. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
645 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
646 For example: |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
647 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
648 How many ways can three items be grouped into pairs? |
6574 | 649 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
650 @example |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
651 @group |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
652 nchoosek (3, 2) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
653 @result{} 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
654 @end group |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
655 @end example |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
656 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
657 What are the possible pairs? |
9210
a7a9eecc07b5
Change recommendation for writing documentation to favor @tex
Rik <rdrider0-list@yahoo.com>
parents:
9209
diff
changeset
|
658 |
14093
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
659 @example |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
660 @group |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
661 nchoosek (1:3, 2) |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
662 @result{} 1 2 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
663 1 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
664 2 3 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
665 @end group |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
666 @end example |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
667 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
668 @code{nchoosek} works only for non-negative, integer arguments. Use |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
669 @code{bincoeff} for non-integer and negative scalar arguments, or for |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
670 computing many binomial coefficients at once with vector inputs for @var{n} |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
671 or @var{k}. |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
672 |
050bc580cb60
doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12576
diff
changeset
|
673 @seealso{bincoeff, perms} |
6574 | 674 @end deftypefn |
675 | |
676 @end iftex |