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