home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / calc.info-16 (.txt) < prev    next >
GNU Info File  |  1994-12-22  |  50KB  |  788 lines

  1. This is Info file calc.info, produced by Makeinfo-1.55 from the input
  2. file calc.texinfo.
  3.    This file documents Calc, the GNU Emacs calculator.
  4.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the section entitled "GNU General Public License" is included
  11. exactly as in the original, and provided that the entire resulting
  12. derived work is distributed under the terms of a permission notice
  13. identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the section entitled "GNU General Public License"
  17. may be included in a translation approved by the author instead of in
  18. the original English.
  19. File: calc.info,  Node: Manipulating Vectors,  Next: Vector and Matrix Arithmetic,  Prev: Extracting Elements,  Up: Matrix Functions
  20. Manipulating Vectors
  21. ====================
  22. The `v l' (`calc-vlength') [`vlen'] command computes the length of a
  23. vector.  The length of a non-vector is considered to be zero.  Note
  24. that matrices are just vectors of vectors for the purposes of this
  25. command.
  26.    With the Hyperbolic flag, `H v l' [`mdims'] computes a vector of the
  27. dimensions of a vector, matrix, or higher-order object.  For example,
  28. `mdims([[a,b,c],[d,e,f]])' returns `[2, 3]' since its argument is a 2x3
  29. matrix.
  30.    The `v f' (`calc-vector-find') [`find'] command searches along a
  31. vector for the first element equal to a given target.  The target is on
  32. the top of the stack; the vector is in the second-to-top position.  If
  33. a match is found, the result is the index of the matching element.
  34. Otherwise, the result is zero.  The numeric prefix argument, if given,
  35. allows you to select any starting index for the search.
  36.    The `v a' (`calc-arrange-vector') [`arrange'] command rearranges a
  37. vector to have a certain number of columns and rows.  The numeric
  38. prefix argument specifies the number of columns; if you do not provide
  39. an argument, you will be prompted for the number of columns.  The
  40. vector or matrix on the top of the stack is "flattened" into a plain
  41. vector.  If the number of columns is nonzero, this vector is then
  42. formed into a matrix by taking successive groups of N elements.  If the
  43. number of columns does not evenly divide the number of elements in the
  44. vector, the last row will be short and the result will not be suitable
  45. for use as a matrix.  For example, with the matrix `[[1, 2], [3, 4]]'
  46. on the stack, `v a 4' produces `[[1, 2, 3, 4]]' (a 1x4 matrix), `v a 1'
  47. produces `[[1], [2], [3], [4]]' (a 4x1 matrix), `v a 2' produces `[[1,
  48. 2], [3, 4]]' (the original 2x2 matrix), `v a 3' produces `[[1, 2, 3],
  49. [4]]' (not a matrix), and `v a 0' produces the flattened list `[1, 2,
  50. 3, 4]'.
  51.    The `V S' (`calc-sort') [`sort'] command sorts the elements of a
  52. vector into increasing order.  Real numbers, real infinities, and
  53. constant interval forms come first in this ordering; next come other
  54. kinds of numbers, then variables (in alphabetical order), then finally
  55. come formulas and other kinds of objects; these are sorted according to
  56. a kind of lexicographic ordering with the useful property that one
  57. vector is less or greater than another if the first corresponding
  58. unequal elements are less or greater, respectively.  Since quoted
  59. strings are stored by Calc internally as vectors of ASCII character
  60. codes (*note Strings::.), this means vectors of strings are also sorted
  61. into alphabetical order by this command.
  62.    The `I V S' [`rsort'] command sorts a vector into decreasing order.
  63.    The `V G' (`calc-grade') [`grade', `rgrade'] command produces an
  64. index table or permutation vector which, if applied to the input vector
  65. (as the index of `C-u v r', say), would sort the vector.  A permutation
  66. vector is just a vector of integers from 1 to N, where each integer
  67. occurs exactly once.  One application of this is to sort a matrix of
  68. data rows using one column as the sort key; extract that column, grade
  69. it with `V G', then use the result to reorder the original matrix with
  70. `C-u v r'.  Another interesting property of the `V G' command is that,
  71. if the input is itself a permutation vector, the result will be the
  72. inverse of the permutation.  The inverse of an index table is a rank
  73. table, whose Kth element says where the Kth original vector element
  74. will rest when the vector is sorted.  To get a rank table, just use `V
  75. G V G'.
  76.    With the Inverse flag, `I V G' produces an index table that would
  77. sort the input into decreasing order.  Note that `V S' and `V G' use a
  78. "stable" sorting algorithm, i.e., any two elements which are equal will
  79. not be moved out of their original order.  Generally there is no way to
  80. tell with `V S', since two elements which are equal look the same, but
  81. with `V G' this can be an important issue.  In the matrix-of-rows
  82. example, suppose you have names and telephone numbers as two columns and
  83. you wish to sort by phone number primarily, and by name when the numbers
  84. are equal.  You can sort the data matrix by names first, and then again
  85. by phone numbers.  Because the sort is stable, any two rows with equal
  86. phone numbers will remain sorted by name even after the second sort.
  87.    The `V H' (`calc-histogram') [`histogram'] command builds a
  88. histogram of a vector of numbers.  Vector elements are assumed to be
  89. integers or real numbers in the range [0..N) for some "number of bins"
  90. N, which is the numeric prefix argument given to the command.  The
  91. result is a vector of N counts of how many times each value appeared in
  92. the original vector.  Non-integers in the input are rounded down to
  93. integers.  Any vector elements outside the specified range are ignored.
  94. (You can tell if elements have been ignored by noting that the counts
  95. in the result vector don't add up to the length of the input vector.)
  96.    With the Hyperbolic flag, `H V H' pulls two vectors from the stack.
  97. The second-to-top vector is the list of numbers as before.  The top
  98. vector is an equal-sized list of "weights" to attach to the elements of
  99. the data vector.  For example, if the first data element is 4.2 and the
  100. first weight is 10, then 10 will be added to bin 4 of the result
  101. vector.  Without the hyperbolic flag, every element has a weight of one.
  102.    The `v t' (`calc-transpose') [`trn'] command computes the transpose
  103. of the matrix at the top of the stack.  If the argument is a plain
  104. vector, it is treated as a row vector and transposed into a one-column
  105. matrix.
  106.    The `v v' (`calc-reverse-vector') [`vec'] command reverses a vector
  107. end-for-end.  Given a matrix, it reverses the order of the rows.  (To
  108. reverse the columns instead, just use `v t v v v t'.  The same
  109. principle can be used to apply other vector commands to the columns of
  110. a matrix.)
  111.    The `v m' (`calc-mask-vector') [`vmask'] command uses one vector as
  112. a mask to extract elements of another vector.  The mask is in the
  113. second-to-top position; the target vector is on the top of the stack.
  114. These vectors must have the same length.  The result is the same as the
  115. target vector, but with all elements which correspond to zeros in the
  116. mask vector deleted.  Thus, for example, `vmask([1, 0, 1, 0, 1], [a, b,
  117. c, d, e])' produces `[a, c, e]'.  *Note Logical Operations::.
  118.    The `v e' (`calc-expand-vector') [`vexp'] command expands a vector
  119. according to another mask vector.  The result is a vector the same
  120. length as the mask, but with nonzero elements replaced by successive
  121. elements from the target vector.  The length of the target vector is
  122. normally the number of nonzero elements in the mask.  If the target
  123. vector is longer, its last few elements are lost.  If the target vector
  124. is shorter, the last few nonzero mask elements are left unreplaced in
  125. the result.  Thus `vexp([2, 0, 3, 0, 7], [a, b])' produces `[a, 0, b,
  126. 0, 7]'.
  127.    With the Hyperbolic flag, `H v e' takes a filler value from the top
  128. of the stack; the mask and target vectors come from the third and
  129. second ele