File: Utility-Functions.html

package info (click to toggle)
octave3.2 3.2.4-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 62,936 kB
  • ctags: 37,353
  • sloc: cpp: 219,497; fortran: 116,336; ansic: 10,264; sh: 5,508; makefile: 4,245; lex: 3,573; yacc: 3,062; objc: 2,042; lisp: 1,692; awk: 860; perl: 844
file content (590 lines) | stat: -rw-r--r-- 29,817 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
<html lang="en">
<head>
<title>Utility Functions - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Arithmetic.html#Arithmetic" title="Arithmetic">
<link rel="prev" href="Sums-and-Products.html#Sums-and-Products" title="Sums and Products">
<link rel="next" href="Special-Functions.html#Special-Functions" title="Special Functions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Utility-Functions"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="Special-Functions.html#Special-Functions">Special Functions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Sums-and-Products.html#Sums-and-Products">Sums and Products</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Arithmetic.html#Arithmetic">Arithmetic</a>
<hr>
</div>

<h3 class="section">17.5 Utility Functions</h3>

<!-- mappers.cc -->
<p><a name="doc_002dceil"></a>

<div class="defun">
&mdash; Mapping Function:  <b>ceil</b> (<var>x</var>)<var><a name="index-ceil-1436"></a></var><br>
<blockquote><p>Return the smallest integer not less than <var>x</var>.  This is equivalent to
rounding towards positive infinity.  If <var>x</var> is
complex, return <code>ceil (real (</code><var>x</var><code>)) + ceil (imag (</code><var>x</var><code>)) * I</code>.
     <pre class="example">          ceil ([-2.7, 2.7])
               -2   3
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfloor.html#doc_002dfloor">floor</a>, <a href="doc_002dround.html#doc_002dround">round</a>, <a href="doc_002dfix.html#doc_002dfix">fix</a>. 
</p></blockquote></div>

<!-- ./linear-algebra/cross.m -->
   <p><a name="doc_002dcross"></a>

<div class="defun">
&mdash; Function File:  <b>cross</b> (<var>x, y</var>)<var><a name="index-cross-1437"></a></var><br>
&mdash; Function File:  <b>cross</b> (<var>x, y, dim</var>)<var><a name="index-cross-1438"></a></var><br>
<blockquote><p>Compute the vector cross product of two 3-dimensional vectors
<var>x</var> and <var>y</var>.

     <pre class="example">          cross ([1,1,0], [0,1,1])
                [ 1; -1; 1 ]
</pre>
        <p>If <var>x</var> and <var>y</var> are matrices, the cross product is applied
along the first dimension with 3 elements.  The optional argument
<var>dim</var> forces the cross product to be calculated along
the specified dimension. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddot.html#doc_002ddot">dot</a>. 
</p></blockquote></div>

<!-- ./general/del2.m -->
   <p><a name="doc_002ddel2"></a>

<div class="defun">
&mdash; Function File: <var>d</var> = <b>del2</b> (<var>m</var>)<var><a name="index-del2-1439"></a></var><br>
&mdash; Function File: <var>d</var> = <b>del2</b> (<var>m, h</var>)<var><a name="index-del2-1440"></a></var><br>
&mdash; Function File: <var>d</var> = <b>del2</b> (<var>m, dx, dy, <small class="dots">...</small></var>)<var><a name="index-del2-1441"></a></var><br>
<blockquote>
        <p>Calculate the discrete Laplace
operator. 
For a 2-dimensional matrix <var>m</var> this is defined as

     <pre class="example">                1    / d^2            d^2         \
          D  = --- * | ---  M(x,y) +  ---  M(x,y) |
                4    \ dx^2           dy^2        /
</pre>
        <p>For N-dimensional arrays the sum in parentheses is expanded to include second derivatives
over the additional higher dimensions.

        <p>The spacing between evaluation points may be defined by <var>h</var>, which is a
scalar defining the equidistant spacing in all dimensions.  Alternatively,
the spacing in each dimension may be defined separately by <var>dx</var>, <var>dy</var>,
etc.  A scalar spacing argument defines equidistant spacing, whereas a vector
argument can be used to specify variable spacing.  The length of the spacing vectors
must match the respective dimension of <var>m</var>.  The default spacing value
is 1.

        <p>At least 3 data points are needed for each dimension.  Boundary points are
calculated from the linear extrapolation of interior points.

     <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dgradient.html#doc_002dgradient">gradient</a>, <a href="doc_002ddiff.html#doc_002ddiff">diff</a>. 
</p></blockquote></div>

<!-- ./specfun/factor.m -->
   <p><a name="doc_002dfactor"></a>

<div class="defun">
&mdash; Function File: <var>p</var> = <b>factor</b> (<var>q</var>)<var><a name="index-factor-1442"></a></var><br>
&mdash; Function File: [<var>p</var>, <var>n</var>] = <b>factor</b> (<var>q</var>)<var><a name="index-factor-1443"></a></var><br>
<blockquote>
        <p>Return prime factorization of <var>q</var>.  That is, <code>prod (</code><var>p</var><code>)
== </code><var>q</var> and every element of <var>p</var> is a prime number.  If
<var>q</var><code> == 1</code>, returns 1.

        <p>With two output arguments, return the unique primes <var>p</var> and
their multiplicities.  That is, <code>prod (</code><var>p</var><code> .^ </code><var>n</var><code>) ==
</code><var>q</var>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dgcd.html#doc_002dgcd">gcd</a>, <a href="doc_002dlcm.html#doc_002dlcm">lcm</a>. 
</p></blockquote></div>

<!-- ./specfun/factorial.m -->
   <p><a name="doc_002dfactorial"></a>

<div class="defun">
&mdash; Function File:  <b>factorial</b> (<var>n</var>)<var><a name="index-factorial-1444"></a></var><br>
<blockquote><p>Return the factorial of <var>n</var> where <var>n</var> is a positive integer.  If
<var>n</var> is a scalar, this is equivalent to <code>prod (1:</code><var>n</var><code>)</code>.  For
vector or matrix arguments, return the factorial of each element in the
array.  For non-integers see the generalized factorial function
<code>gamma</code>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dprod.html#doc_002dprod">prod</a>, <a href="doc_002dgamma.html#doc_002dgamma">gamma</a>. 
</p></blockquote></div>

<!-- mappers.cc -->
   <p><a name="doc_002dfix"></a>

<div class="defun">
&mdash; Mapping Function:  <b>fix</b> (<var>x</var>)<var><a name="index-fix-1445"></a></var><br>
<blockquote><p>Truncate fractional portion of <var>x</var> and return the integer portion.  This
is equivalent to rounding towards zero.  If <var>x</var> is complex, return
<code>fix (real (</code><var>x</var><code>)) + fix (imag (</code><var>x</var><code>)) * I</code>.
     <pre class="example">          fix ([-2.7, 2.7])
              -2   2
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dceil.html#doc_002dceil">ceil</a>, <a href="doc_002dfloor.html#doc_002dfloor">floor</a>, <a href="doc_002dround.html#doc_002dround">round</a>. 
</p></blockquote></div>

<!-- mappers.cc -->
   <p><a name="doc_002dfloor"></a>

<div class="defun">
&mdash; Mapping Function:  <b>floor</b> (<var>x</var>)<var><a name="index-floor-1446"></a></var><br>
<blockquote><p>Return the largest integer not greater than <var>x</var>.  This is equivalent to
rounding towards negative infinity.  If <var>x</var> is
complex, return <code>floor (real (</code><var>x</var><code>)) + floor (imag (</code><var>x</var><code>)) * I</code>.
     <pre class="example">          floor ([-2.7, 2.7])
                -3   2
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dceil.html#doc_002dceil">ceil</a>, <a href="doc_002dround.html#doc_002dround">round</a>, <a href="doc_002dfix.html#doc_002dfix">fix</a>. 
</p></blockquote></div>

<!-- data.cc -->
   <p><a name="doc_002dfmod"></a>

<div class="defun">
&mdash; Mapping Function:  <b>fmod</b> (<var>x, y</var>)<var><a name="index-fmod-1447"></a></var><br>
<blockquote><p>Compute the floating point remainder of dividing <var>x</var> by <var>y</var>
using the C library function <code>fmod</code>.  The result has the same
sign as <var>x</var>.  If <var>y</var> is zero, the result is implementation-dependent. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dmod.html#doc_002dmod">mod</a>, <a href="doc_002drem.html#doc_002drem">rem</a>. 
</p></blockquote></div>

<!-- ./DLD-FUNCTIONS/gcd.cc -->
   <p><a name="doc_002dgcd"></a>

<div class="defun">
&mdash; Loadable Function: <var>g</var> = <b>gcd</b> (<var>a</var>)<var><a name="index-gcd-1448"></a></var><br>
&mdash; Loadable Function: <var>g</var> = <b>gcd</b> (<var>a1, a2, <small class="dots">...</small></var>)<var><a name="index-gcd-1449"></a></var><br>
&mdash; Loadable Function: [<var>g</var>, <var>v1</var>, <small class="dots">...</small>] = <b>gcd</b> (<var>a1, a2, <small class="dots">...</small></var>)<var><a name="index-gcd-1450"></a></var><br>
<blockquote>
        <p>Compute the greatest common divisor of the elements of <var>a</var>.  If more
than one argument is given all arguments must be the same size or scalar. 
  In this case the greatest common divisor is calculated for each element
individually.  All elements must be integers.  For example,

     <pre class="example">          gcd ([15, 20])
                5
</pre>
        <p class="noindent">and

     <pre class="example">          gcd ([15, 9], [20, 18])
                5  9
</pre>
        <p>Optional return arguments <var>v1</var>, etc., contain integer vectors such
that,

     <pre class="example">          <var>g</var> = <var>v1</var> .* <var>a1</var> + <var>v2</var> .* <var>a2</var> + ...
</pre>
        <p>For backward compatibility with previous versions of this function, when
all arguments are scalar, a single return argument <var>v1</var> containing
all of the values of <var>v1</var>, <small class="dots">...</small> is acceptable. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dlcm.html#doc_002dlcm">lcm</a>, <a href="doc_002dfactor.html#doc_002dfactor">factor</a>. 
</p></blockquote></div>

<!-- ./general/gradient.m -->
   <p><a name="doc_002dgradient"></a>

<div class="defun">
&mdash; Function File: <var>dx</var> = <b>gradient</b> (<var>m</var>)<var><a name="index-gradient-1451"></a></var><br>
&mdash; Function File: [<var>dx</var>, <var>dy</var>, <var>dz</var>, <small class="dots">...</small>] = <b>gradient</b> (<var>m</var>)<var><a name="index-gradient-1452"></a></var><br>
&mdash; Function File: [<small class="dots">...</small>] = <b>gradient</b> (<var>m, s</var>)<var><a name="index-gradient-1453"></a></var><br>
&mdash; Function File: [<small class="dots">...</small>] = <b>gradient</b> (<var>m, x, y, z, <small class="dots">...</small></var>)<var><a name="index-gradient-1454"></a></var><br>
&mdash; Function File: [<small class="dots">...</small>] = <b>gradient</b> (<var>f, x0</var>)<var><a name="index-gradient-1455"></a></var><br>
&mdash; Function File: [<small class="dots">...</small>] = <b>gradient</b> (<var>f, x0, s</var>)<var><a name="index-gradient-1456"></a></var><br>
&mdash; Function File: [<small class="dots">...</small>] = <b>gradient</b> (<var>f, x0, x, y, <small class="dots">...</small></var>)<var><a name="index-gradient-1457"></a></var><br>
<blockquote>
        <p>Calculate the gradient of sampled data or a function.  If <var>m</var>
is a vector, calculate the one-dimensional gradient of <var>m</var>.  If
<var>m</var> is a matrix the gradient is calculated for each dimension.

        <p><code>[</code><var>dx</var><code>, </code><var>dy</var><code>] = gradient (</code><var>m</var><code>)</code> calculates the one
dimensional gradient for <var>x</var> and <var>y</var> direction if <var>m</var> is a
matrix.  Additional return arguments can be use for multi-dimensional
matrices.

        <p>A constant spacing between two points can be provided by the
<var>s</var> parameter.  If <var>s</var> is a scalar, it is assumed to be the spacing
for all dimensions. 
Otherwise, separate values of the spacing can be supplied by
the <var>x</var>, <small class="dots">...</small> arguments.  Scalar values specify an equidistant spacing. 
Vector values for the <var>x</var>, <small class="dots">...</small> arguments specify the coordinate for that
dimension.  The length must match their respective dimension of <var>m</var>.

        <p>At boundary points a linear extrapolation is applied.  Interior points
are calculated with the first approximation of the numerical gradient

     <pre class="example">          y'(i) = 1/(x(i+1)-x(i-1)) * (y(i-1)-y(i+1)).
</pre>
        <p>If the first argument <var>f</var> is a function handle, the gradient of the
function at the points in <var>x0</var> is approximated using central
difference.  For example, <code>gradient (@cos, 0)</code> approximates the
gradient of the cosine function in the point x0 = 0.  As with
sampled data, the spacing values between the points from which the
gradient is estimated can be set via the <var>s</var> or <var>dx</var>,
<var>dy</var>, <small class="dots">...</small> arguments.  By default a spacing of 1 is used. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddiff.html#doc_002ddiff">diff</a>, <a href="doc_002ddel2.html#doc_002ddel2">del2</a>. 
</p></blockquote></div>

<!-- data.cc -->
   <p><a name="doc_002dhypot"></a>

<div class="defun">
&mdash; Built-in Function:  <b>hypot</b> (<var>x, y</var>)<var><a name="index-hypot-1458"></a></var><br>
<blockquote><p>Compute the element-by-element square root of the sum of the squares of
<var>x</var> and <var>y</var>.  This is equivalent to
<code>sqrt (</code><var>x</var><code>.^2 + </code><var>y</var><code>.^2)</code>, but calculated in a manner that
avoids overflows for large values of <var>x</var> or <var>y</var>. 
</p></blockquote></div>

<!-- ./elfun/lcm.m -->
   <p><a name="doc_002dlcm"></a>

<div class="defun">
&mdash; Mapping Function:  <b>lcm</b> (<var>x</var>)<var><a name="index-lcm-1459"></a></var><br>
&mdash; Mapping Function:  <b>lcm</b> (<var>x, <small class="dots">...</small></var>)<var><a name="index-lcm-1460"></a></var><br>
<blockquote><p>Compute the least common multiple of the elements of <var>x</var>, or
of the list of all arguments.  For example,

     <pre class="example">          lcm (a1, ..., ak)
</pre>
        <p class="noindent">is the same as

     <pre class="example">          lcm ([a1, ..., ak]).
</pre>
        <p>All elements must be the same size or scalar. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfactor.html#doc_002dfactor">factor</a>, <a href="doc_002dgcd.html#doc_002dgcd">gcd</a>. 
</p></blockquote></div>

<!-- ./miscellaneous/list_primes.m -->
   <p><a name="doc_002dlist_005fprimes"></a>

<div class="defun">
&mdash; Function File:  <b>list_primes</b> (<var>n</var>)<var><a name="index-list_005fprimes-1461"></a></var><br>
<blockquote><p>List the first <var>n</var> primes.  If <var>n</var> is unspecified, the first
25 primes are listed.

        <p>The algorithm used is from page 218 of the TeXbook. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dprimes.html#doc_002dprimes">primes</a>, <a href="doc_002disprime.html#doc_002disprime">isprime</a>. 
</p></blockquote></div>

<!-- ./DLD-FUNCTIONS/max.cc -->
   <p><a name="doc_002dmax"></a>

<div class="defun">
&mdash; Loadable Function:  <b>max</b> (<var>x</var>)<var><a name="index-max-1462"></a></var><br>
&mdash; Loadable Function:  <b>max</b> (<var>x, y</var>)<var><a name="index-max-1463"></a></var><br>
&mdash; Loadable Function:  <b>max</b> (<var>x, y, dim</var>)<var><a name="index-max-1464"></a></var><br>
&mdash; Loadable Function: [<var>w</var>, <var>iw</var>] = <b>max</b> (<var>x</var>)<var><a name="index-max-1465"></a></var><br>
<blockquote><p>For a vector argument, return the maximum value.  For a matrix
argument, return the maximum value from each column, as a row
vector, or over the dimension <var>dim</var> if defined.  For two matrices
(or a matrix and scalar), return the pair-wise maximum. 
Thus,

     <pre class="example">          max (max (<var>x</var>))
</pre>
        <p class="noindent">returns the largest element of the matrix <var>x</var>, and

     <pre class="example">          max (2:5, pi)
                3.1416  3.1416  4.0000  5.0000
</pre>
        <p class="noindent">compares each element of the range <code>2:5</code> with <code>pi</code>, and
returns a row vector of the maximum values.

        <p>For complex arguments, the magnitude of the elements are used for
comparison.

        <p>If called with one input and two output arguments,
<code>max</code> also returns the first index of the
maximum value(s).  Thus,

     <pre class="example">          [x, ix] = max ([1, 3, 5, 2, 5])
                x = 5
                  ix = 3
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dmin.html#doc_002dmin">min</a>, <a href="doc_002dcummax.html#doc_002dcummax">cummax</a>, <a href="doc_002dcummin.html#doc_002dcummin">cummin</a>. 
</p></blockquote></div>

<!-- ./DLD-FUNCTIONS/max.cc -->
   <p><a name="doc_002dmin"></a>

<div class="defun">
&mdash; Loadable Function:  <b>min</b> (<var>x</var>)<var><a name="index-min-1466"></a></var><br>
&mdash; Loadable Function:  <b>min</b> (<var>x, y</var>)<var><a name="index-min-1467"></a></var><br>
&mdash; Loadable Function:  <b>min</b> (<var>x, y, dim</var>)<var><a name="index-min-1468"></a></var><br>
&mdash; Loadable Function: [<var>w</var>, <var>iw</var>] = <b>min</b> (<var>x</var>)<var><a name="index-min-1469"></a></var><br>
<blockquote><p>For a vector argument, return the minimum value.  For a matrix
argument, return the minimum value from each column, as a row
vector, or over the dimension <var>dim</var> if defined.  For two matrices
(or a matrix and scalar), return the pair-wise minimum. 
Thus,

     <pre class="example">          min (min (<var>x</var>))
</pre>
        <p class="noindent">returns the smallest element of <var>x</var>, and

     <pre class="example">          min (2:5, pi)
                2.0000  3.0000  3.1416  3.1416
</pre>
        <p class="noindent">compares each element of the range <code>2:5</code> with <code>pi</code>, and
returns a row vector of the minimum values.

        <p>For complex arguments, the magnitude of the elements are used for
comparison.

        <p>If called with one input and two output arguments,
<code>min</code> also returns the first index of the
minimum value(s).  Thus,

     <pre class="example">          [x, ix] = min ([1, 3, 0, 2, 0])
                x = 0
                  ix = 3
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dmax.html#doc_002dmax">max</a>, <a href="doc_002dcummin.html#doc_002dcummin">cummin</a>, <a href="doc_002dcummax.html#doc_002dcummax">cummax</a>. 
</p></blockquote></div>

<!-- ./DLD-FUNCTIONS/max.cc -->
   <p><a name="doc_002dcummax"></a>

<div class="defun">
&mdash; Loadable Function:  <b>cummax</b> (<var>x</var>)<var><a name="index-cummax-1470"></a></var><br>
&mdash; Loadable Function:  <b>cummax</b> (<var>x, dim</var>)<var><a name="index-cummax-1471"></a></var><br>
&mdash; Loadable Function: [<var>w</var>, <var>iw</var>] = <b>cummax</b> (<var>x</var>)<var><a name="index-cummax-1472"></a></var><br>
<blockquote><p>Return the cumulative maximum values along dimension <var>dim</var>.  If <var>dim</var>
is unspecified it defaults to column-wise operation.  For example,

     <pre class="example">          cummax ([1 3 2 6 4 5])
                1  3  3  6  6  6
</pre>
        <p>The call
     <pre class="example">          [w, iw] = cummax (x, dim)
</pre>
        <p class="noindent">is equivalent to the following code:
     <pre class="example">          w = iw = zeros (size (x));
          idxw = idxx = repmat ({':'}, 1, ndims (x));
          for i = 1:size (x, dim)
            idxw{dim} = i; idxx{dim} = 1:i;
            [w(idxw{:}), iw(idxw{:})] = max(x(idxx{:}), [], dim);
          endfor
</pre>
        <p class="noindent">but computed in a much faster manner. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcummin.html#doc_002dcummin">cummin</a>, <a href="doc_002dmax.html#doc_002dmax">max</a>, <a href="doc_002dmin.html#doc_002dmin">min</a>. 
</p></blockquote></div>

<!-- ./DLD-FUNCTIONS/max.cc -->
   <p><a name="doc_002dcummin"></a>

<div class="defun">
&mdash; Loadable Function:  <b>cummin</b> (<var>x</var>)<var><a name="index-cummin-1473"></a></var><br>
&mdash; Loadable Function:  <b>cummin</b> (<var>x, dim</var>)<var><a name="index-cummin-1474"></a></var><br>
&mdash; Loadable Function: [<var>w</var>, <var>iw</var>] = <b>cummin</b> (<var>x</var>)<var><a name="index-cummin-1475"></a></var><br>
<blockquote><p>Return the cumulative minimum values along dimension <var>dim</var>.  If <var>dim</var>
is unspecified it defaults to column-wise operation.  For example,

     <pre class="example">          cummin ([5 4 6 2 3 1])
                5  4  4  2  2  1
</pre>
        <p>The call
     <pre class="example">            [w, iw] = cummin (x, dim)
</pre>
        <p class="noindent">is equivalent to the following code:
     <pre class="example">          w = iw = zeros (size (x));
          idxw = idxx = repmat ({':'}, 1, ndims (x));
          for i = 1:size (x, dim)
            idxw{dim} = i; idxx{dim} = 1:i;
            [w(idxw{:}), iw(idxw{:})] = min(x(idxx{:}), [], dim);
          endfor
</pre>
        <p class="noindent">but computed in a much faster manner. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcummax.html#doc_002dcummax">cummax</a>, <a href="doc_002dmin.html#doc_002dmin">min</a>, <a href="doc_002dmax.html#doc_002dmax">max</a>. 
</p></blockquote></div>

<!-- ./general/mod.m -->
   <p><a name="doc_002dmod"></a>

<div class="defun">
&mdash; Mapping Function:  <b>mod</b> (<var>x, y</var>)<var><a name="index-mod-1476"></a></var><br>
<blockquote><p>Compute the modulo of <var>x</var> and <var>y</var>.  Conceptually this is given by

     <pre class="example">          x - y .* floor (x ./ y)
</pre>
        <p>and is written such that the correct modulus is returned for
integer types.  This function handles negative values correctly.  That
is, <code>mod (-1, 3)</code> is 2, not -1, as <code>rem (-1, 3)</code> returns. 
<code>mod (</code><var>x</var><code>, 0)</code> returns <var>x</var>.

        <p>An error results if the dimensions of the arguments do not agree, or if
either of the arguments is complex. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002drem.html#doc_002drem">rem</a>, <a href="doc_002dfmod.html#doc_002dfmod">fmod</a>. 
</p></blockquote></div>

<!-- ./specfun/primes.m -->
   <p><a name="doc_002dprimes"></a>

<div class="defun">
&mdash; Function File:  <b>primes</b> (<var>n</var>)<var><a name="index-primes-1477"></a></var><br>
<blockquote>
        <p>Return all primes up to <var>n</var>.

        <p>The algorithm used is the Sieve of Erastothenes.

        <p>Note that if you need a specific number of primes you can use the
fact the distance from one prime to the next is, on average,
proportional to the logarithm of the prime.  Integrating, one finds
that there are about k primes less than
k*log(5*k). 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dlist_005fprimes.html#doc_002dlist_005fprimes">list_primes</a>, <a href="doc_002disprime.html#doc_002disprime">isprime</a>. 
</p></blockquote></div>

<!-- ./general/rem.m -->
   <p><a name="doc_002drem"></a>

<div class="defun">
&mdash; Mapping Function:  <b>rem</b> (<var>x, y</var>)<var><a name="index-rem-1478"></a></var><br>
<blockquote><p>Return the remainder of the division <var>x</var><code> / </code><var>y</var>, computed
using the expression

     <pre class="example">          x - y .* fix (x ./ y)
</pre>
        <p>An error message is printed if the dimensions of the arguments do not
agree, or if either of the arguments is complex. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dmod.html#doc_002dmod">mod</a>, <a href="doc_002dfmod.html#doc_002dfmod">fmod</a>. 
</p></blockquote></div>

<!-- mappers.cc -->
   <p><a name="doc_002dround"></a>

<div class="defun">
&mdash; Mapping Function:  <b>round</b> (<var>x</var>)<var><a name="index-round-1479"></a></var><br>
<blockquote><p>Return the integer nearest to <var>x</var>.  If <var>x</var> is complex, return
<code>round (real (</code><var>x</var><code>)) + round (imag (</code><var>x</var><code>)) * I</code>.
     <pre class="example">          round ([-2.7, 2.7])
                -3   3
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dceil.html#doc_002dceil">ceil</a>, <a href="doc_002dfloor.html#doc_002dfloor">floor</a>, <a href="doc_002dfix.html#doc_002dfix">fix</a>. 
</p></blockquote></div>

<!-- mappers.cc -->
   <p><a name="doc_002droundb"></a>

<div class="defun">
&mdash; Mapping Function:  <b>roundb</b> (<var>x</var>)<var><a name="index-roundb-1480"></a></var><br>
<blockquote><p>Return the integer nearest to <var>x</var>.  If there are two nearest
integers, return the even one (banker's rounding).  If <var>x</var> is complex,
return <code>roundb (real (</code><var>x</var><code>)) + roundb (imag (</code><var>x</var><code>)) * I</code>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dround.html#doc_002dround">round</a>. 
</p></blockquote></div>

<!-- mappers.cc -->
   <p><a name="doc_002dsign"></a>

<div class="defun">
&mdash; Mapping Function:  <b>sign</b> (<var>x</var>)<var><a name="index-sign-1481"></a></var><br>
<blockquote><p>Compute the <dfn>signum</dfn> function, which is defined as

     <pre class="example">                     -1, x &lt; 0;
          sign (x) =  0, x = 0;
                      1, x &gt; 0.
</pre>
        <p>For complex arguments, <code>sign</code> returns <code>x ./ abs (</code><var>x</var><code>)</code>. 
</p></blockquote></div>

   </body></html>