home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
info
/
calc.info-19
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-12-22
|
48KB
|
780 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: Customizing the Integrator, Next: Numerical Integration, Prev: Integration, Up: Calculus
Customizing the Integrator
--------------------------
Calc has two built-in rewrite rules called `IntegRules' and
`IntegAfterRules' which you can edit to define new integration methods.
*Note Rewrite Rules::. At each step of the integration process, Calc
wraps the current integrand in a call to the fictitious function
`integtry(EXPR,VAR)', where EXPR is the integrand and VAR is the
integration variable. If your rules rewrite this to be a plain formula
(not a call to `integtry'), then Calc will use this formula as the
integral of EXPR. For example, the rule `integtry(mysin(x),x) :=
-mycos(x)' would define a rule to integrate a function `mysin' that
acts like the sine function. Then, putting `4 mysin(2y+1)' on the
stack and typing `a i y' will produce the integral `-2 mycos(2y+1)'.
Note that Calc has automatically made various transformations on the
integral to allow it to use your rule; integral tables generally give
rules for `mysin(a x + b)', but you don't need to use this much
generality in your `IntegRules'.
As a more serious example, the expression `exp(x)/x' cannot be
integrated in terms of the standard functions, so the "exponential
integral" function `Ei(x)' was invented to describe it. We can get
Calc to do this integral in terms of a made-up `Ei' function by adding
the rule `[integtry(exp(x)/x, x) := Ei(x)]' to `IntegRules'. Now
entering `exp(2x)/x' on the stack and typing `a i x' yields `Ei(2 x)'.
This new rule will work with Calc's various built-in integration
methods (such as integration by substitution) to solve a variety of
other problems involving `Ei': For example, now Calc will also be able
to integrate `exp(exp(x))' and `ln(ln(x))' (to get `Ei(exp(x))' and `x
ln(ln(x)) - Ei(ln(x))', respectively).
Your rule may do further integration by calling `integ'. For
example, `integtry(twice(u),x) := twice(integ(u))' allows Calc to
integrate `twice(sin(x))' to get `twice(-cos(x))'. Note that `integ'
was called with only one argument. This notation is allowed only
within `IntegRules'; it means "integrate this with respect to the same
integration variable." If Calc is unable to integrate `u', the
integration that invoked `IntegRules' also fails. Thus integrating
`twice(f(x))' fails, returning the unevaluated integral
`integ(twice(f(x)), x)'. It is still legal to call `integ' with two or
more arguments, however; in this case, if `u' is not integrable,
`twice' itself will still be integrated: If the above rule is changed
to `... := twice(integ(u,x))', then integrating `twice(f(x))' will
yield `twice(integ(f(x),x))'.
If a rule instead produces the formula `integsubst(SEXPR, SVAR)',
either replacing the top-level `integtry' call or nested anywhere
inside the expression, then Calc will apply the substitution `U =
SEXPR(SVAR)' to try to integrate the original EXPR. For example, the
rule `sqrt(a) := integsubst(sqrt(x),x)' says that if Calc ever finds a
square root in the integrand, it should attempt the substitution `u =
sqrt(x)'. (This particular rule is unnecessary because Calc always
tries "obvious" substitutions where SEXPR actually appears in the
integrand.) The variable SVAR may be the same as the VAR that appeared
in the call to `integtry', but it need not be.
When integrating according to an `integsubst', Calc uses the
equation solver to find the inverse of SEXPR (if the integrand refers
to VAR anywhere except in subexpressions that exactly match SEXPR). It
uses the differentiator to find the derivative of SEXPR and/or its
inverse (it has two methods that use one derivative or the other). You
can also specify these items by adding extra arguments to the
`integsubst' your rules construct; the general form is
`integsubst(SEXPR, SVAR, SINV, SPRIME)', where SINV is the inverse of
SEXPR (still written as a function of SVAR), and SPRIME is the
derivative of SEXPR with respect to SVAR. If you don't specify these
things, and Calc is not able to work them out on its own with the
information it knows, then your substitution rule will work only in
very specific, simple cases.
Calc applies `IntegRules' as if by `C-u 1 a r IntegRules'; in other
words, Calc stops rewriting as soon as any rule in your rule set
succeeds. (If it weren't for this, the `integsubst(sqrt(x),x)' example
above would keep on adding layers of `integsubst' calls forever!)
Another set of rules, stored in `IntegSimpRules', are applied every
time the integrator uses `a s' to simplify an intermediate result. For
example, putting the rule `twice(x) := 2 x' into `IntegSimpRules' would
tell Calc to convert the `twice' function into a form it knows whenever
integration is attempted.
One more way to influence the integrator is to define a function with
the `Z F' command (*note Algebraic Definitions::.). Calc's integrator
automatically expands such functions according to their defining
formulas, even if you originally asked for the function to be left
unevaluated for symbolic arguments. (Certain other Calc systems, such
as the differentiator and the equation solver, also do this.)
Sometimes Calc is able to find a solution to your integral, but it
expresses the result in a way that is unnecessarily complicated. If
this happens, you can either use `integsubst' as described above to try
to hint at a more direct path to the desired result, or you can use
`IntegAfterRules'. This is an extra rule set that runs after the main
integrator returns its result; basically, Calc does an `a r
IntegAfterRules' on the result before showing it to you. (It also does
an `a s', without `IntegSimpRules', after that to further simplify the
result.) For example, Calc's integrator sometimes produces expressions
of the form `ln(1+x) - ln(1-x)'; the default `IntegAfterRules' rewrite
this into the more readable form `2 arctanh(x)'. Note that, unlike
`IntegRules', `IntegSimpRules' and `IntegAfterRules' are applied any
number of times until no further changes are possible. Rewriting by
`IntegAfterRules' occurs only after the main integrator has finished,
not at every step as for `IntegRules' and `IntegSimpRules'.
File: calc.info, Node: Numerical Integration, Next: Taylor Series, Prev: Customizing the Integrator, Up: Calculus
Numerical Integration
---------------------
If you want a purely numerical answer to an integration problem, you can
use the `a I' (`calc-num-integral') [`ninteg'] command. This command
prompts for an integration variable, a lower limit, and an upper limit.
Except for the integration variable, all other variables that appear
in the integrand formula must have stored values. (A stored value, if
any, for the integration variable itself is ignored.)
Numerical integration works by evaluating your formula at many
points in the specified interval. Calc uses an "open Romberg" method;
this means that it does not evaluate the formula actually at the
endpoints (so that it is safe to integrate `sin(x)/x' from zero, for
example). Also, the Romberg method works especially well when the
function being integrated i