home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
info
/
calc.info-13
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-12-22
|
43KB
|
685 lines
This is Info file calc.info, produced by Makeinfo-1.55 from the input
file calc.texinfo.
This file documents Calc, the GNU Emacs calculator.
Copyright (C) 1990, 1991 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the section entitled "GNU General Public License" is included
exactly as in the original, and provided that the entire resulting
derived work is distributed under the terms of a permission notice
identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the section entitled "GNU General Public License"
may be included in a translation approved by the author instead of in
the original English.
File: calc.info, Node: Basic Arithmetic, Next: Integer Truncation, Prev: Arithmetic, Up: Arithmetic
Basic Arithmetic
================
The `+' (`calc-plus') command adds two numbers. The numbers may be any
of the standard Calc data types. The resulting sum is pushed back onto
the stack.
If both arguments of `+' are vectors or matrices (of matching
dimensions), the result is a vector or matrix sum. If one argument is
a vector and the other a scalar (i.e., a non-vector), the scalar is
added to each of the elements of the vector to form a new vector. If
the scalar is not a number, the operation is left in symbolic form:
Suppose you added `x' to the vector `[1,2]'. You may want the result
`[1+x,2+x]', or you may plan to substitute a 2-vector for `x' in the
future. Since the Calculator can't tell which interpretation you want,
it makes the safest assumption. *Note Reducing and Mapping::, for a
way to add `x' to every element of a vector.
If either argument of `+' is a complex number, the result will in
general be complex. If one argument is in rectangular form and the
other polar, the current Polar Mode determines the form of the result.
If Symbolic Mode is enabled, the sum may be left as a formula if the
necessary conversions for polar addition are non-trivial.
If both arguments of `+' are HMS forms, the forms are added
according to the usual conventions of hours-minutes-seconds notation.
If one argument is an HMS form and the other is a number, that number
is converted from degrees or radians (depending on the current Angular
Mode) to HMS format and then the two HMS forms are added.
If one argument of `+' is a date form, the other can be either a
real number, which advances the date by a certain number of days, or an
HMS form, which advances the date by a certain amount of time.
Subtracting two date forms yields the number of days between them.
Adding two date forms is meaningless, but Calc interprets it as the
subtraction of one date form and the negative of the other. (The
negative of a date form can be understood by remembering that dates are
stored as the number of days before or after Jan 1, 1 AD.)
If both arguments of `+' are error forms, the result is an error form
with an appropriately computed standard deviation. If one argument is
an error form and the other is a number, the number is taken to have
zero error. Error forms may have symbolic formulas as their mean
and/or error parts; adding these will produce a symbolic error form
result. However, adding an error form to a plain symbolic formula (as
in `(a +/- b) + c') will not work, for the same reasons just mentioned
for vectors. Instead you must write `(a +/- b) + (c +/- 0)'.
If both arguments of `+' are modulo forms with equal values of `M',
or if one argument is a modulo form and the other a plain number, the
result is a modulo form which represents the sum, modulo `M', of the
two values.
If both arguments of `+' are intervals, the result is an interval
which describes all possible sums of the possible input values. If one
argument is a plain number, it is treated as the interval `[x .. x]'.
If one argument of `+' is an infinity and the other is not, the
result is that same infinity. If both arguments are infinite and in
the same direction, the result is the same infinity, but if they are
infinite in different directions the result is `nan'.
The `-' (`calc-minus') command subtracts two values. The top number
on the stack is subtracted from the one behind it, so that the
computation `5 RET 2 -' produces 3, not -3. All options available for
`+' are available for `-' as well.
The `*' (`calc-times') command multiplies two numbers. If one
argument is a vector and the other a scalar, the scalar is multiplied by
the elements of the vector to produce a new vector. If both arguments
are vectors, the interpretation depends on the dimensions of the
vectors: If both arguments are matrices, a matrix multiplication is
done. If one argument is a matrix and the other a plain vector, the
vector is interpreted as a row vector or column vector, whichever is
dimensionally correct. If both arguments are plain vectors, the result
is a single scalar number which is the dot product of the two vectors.
If one argument of `*' is an HMS form and the other a number, the
HMS form is multiplied by that amount. It is an error to multiply two
HMS forms together, or to attempt any multiplication involving date
forms. Error forms, modulo forms, and intervals can be multiplied; see
the comments for addition of those forms. When two error forms or
intervals are multiplied they are considered to be statistically
independent; thus, `[-2 .. 3] * [-2 .. 3]' is `[-6 .. 9]', whereas
`[-2 .. 3] ^ 2' is `[0 .. 9]'.
The `/' (`calc-divide') command divides two numbers. When dividing
a scalar `B' by a square matrix `A', the computation performed is `B'
times the inverse of `A'. This also occurs if `B' is itself a vector
or matrix, in which case the effect is to solve the set of linear
equations represented by `B'. If `B' is a matrix with the same number
of rows as `A', or a plain vector (which is interpreted here as a
column vector), then the equation `A X = B' is solved for the vector or
matrix `X'. Otherwise, if `B' is a non-square matrix with the same
number of *columns* as `A', the equation `X A = B' is solved. If you
wish a vector `B' to be interpreted as a row vector to be solved as `X
A = B', make it into a one-row matrix with `C-u 1 v p' first. To force
a left-handed solution with a square matrix `B', transpose `A' and `B'
before dividing, then transpose the result.
HMS forms can be divided by real numbers or by other HMS forms.
Error forms can be divided in any combination of ways. Modulo forms
where both values and the modulo are integers can be divided to get an
integer modulo form result. Intervals can be divided; dividing by an
interval that encompasses zero or has zero as a limit will result in an
infinite interval.
The `^' (`calc-power') command raises a number to a power. If the
power is an integer, an exact result is computed using repeated
multiplications. For non-integer powers, Calc uses Newton's method or
logarithms and exponentials. Square matrices can be raised to integer
powers. If either argument is an error (or interval or modulo) form,
the result is also an error (or interval or modulo) form.
If you press the `I' (inverse) key first, the `I ^' command computes
an Nth root: `125 RET 3 I ^' computes the number 5. (This is entirely
equivalent to `125 RET 1:3 ^'.)
The `\' (`calc-idiv') command divides two numbers on the stack to
produce an integer result. It is equivalent to dividing with /, then
rounding down with `F' (`calc-floor'), only a bit more convenient and
efficient. Also, since it is an all-integer operation when the
arguments are integers, it avoids problems that `/ F' would have with
floating-point roundoff.
The `%' (`calc-mod') command performs a "modulo" (or "remainder")
operation. Mathematically, `a%b = a - (a\b)*b', and is defined for all
real numbers `a' and `b' (except `b=0')