1 @c -----------------------------------------------------------------------------
2 @c File : romberg.de.texi
3 @c License : GNU General Public License (GPL)
5 @c Original : romberg.texi revision 28.11.2007
7 @c Revision : 20.08.2011
9 @c This file is part of Maxima -- GPL CAS based on DOE-MACSYMA
10 @c -----------------------------------------------------------------------------
13 * Functions and Variables for romberg::
16 @c -----------------------------------------------------------------------------
17 @node Functions and Variables for romberg, , Top, Top
18 @section Functions and Variables for romberg
19 @c -----------------------------------------------------------------------------
21 @c -----------------------------------------------------------------------------
22 @anchor{function_romberg}
23 @deffn {Function} romberg (@var{expr}, @var{x}, @var{a}, @var{b})
24 @deffnx {Function} romberg (@var{F}, @var{a}, @var{b})
26 Computes a numerical integration by Romberg's method.
28 @code{romberg(@var{expr}, @var{x}, @var{a}, @var{b})} returns an estimate of
29 the integral @code{integrate(@var{expr}, @var{x}, @var{a}, @var{b})}.
30 @var{expr} must be an expression which evaluates to a floating point value
31 when @var{x} is bound to a floating point value.
33 @code{romberg(@var{F}, @var{a}, @var{b})} returns an estimate of the integral
34 @code{integrate(@var{F}(x), x, @var{a}, @var{b})} where @code{x} represents the
35 unnamed, sole argument of @var{F}; the actual argument is not named @code{x}.
36 @var{F} must be a Maxima or Lisp function which returns a floating point value
37 when the argument is a floating point value. @var{F} may name a translated or
38 compiled Maxima function.
40 The accuracy of @code{romberg} is governed by the global variables
41 @mref{rombergabs} and @mrefdot{rombergtol} @code{romberg} terminates
42 successfully when the absolute difference between successive approximations is
43 less than @code{rombergabs}, or the relative difference in successive
44 approximations is less than @code{rombergtol}. Thus when @code{rombergabs} is
45 @code{0.0} (the default) only the relative error test has any effect on
48 @code{romberg} halves the stepsize at most @mref{rombergit} times before it
49 gives up; the maximum number of function evaluations is therefore
50 @code{2^rombergit}. If the error criterion established by @code{rombergabs}
51 and @code{rombergtol} is not satisfied, @code{romberg} prints an error message.
52 @code{romberg} always makes at least @mref{rombergmin} iterations; this is a
53 heuristic intended to prevent spurious termination when the integrand is
56 @code{romberg} repeatedly evaluates the integrand after binding the variable
57 of integration to a specific value (and not before). This evaluation policy
58 makes it possible to nest calls to @code{romberg}, to compute multidimensional
59 integrals. However, the error calculations do not take the errors of nested
60 integrations into account, so errors may be underestimated. Also, methods
61 devised especially for multidimensional problems may yield the same accuracy
62 with fewer function evaluations.
64 @code{load("romberg")} loads this function.
66 See also @ref{Einf@"uhrung in QUADPACK}, a collection of numerical integration
71 A 1-dimensional integration.
74 (%i1) load ("romberg");
75 (%o1) /usr/share/maxima/5.11.0/share/numeric/romberg.lisp
76 (%i2) f(x) := 1/((x - 1)^2 + 1/100) + 1/((x - 2)^2 + 1/1000)
77 + 1/((x - 3)^2 + 1/200);
80 (%o2) f(x) := -------------- + --------------- + --------------
82 (x - 1) + --- (x - 2) + ---- (x - 3) + ---
85 (%i3) rombergtol : 1e-6;
86 (%o3) 9.9999999999999995E-7
89 (%i5) estimate : romberg (f(x), x, -5, 5);
90 (%o5) 173.6730736617464
91 (%i6) exact : integrate (f(x), x, -5, 5);
92 (%o6) 10 sqrt(10) atan(70 sqrt(10))
93 + 10 sqrt(10) atan(30 sqrt(10)) + 10 sqrt(2) atan(80 sqrt(2))
94 + 10 sqrt(2) atan(20 sqrt(2)) + 10 atan(60) + 10 atan(40)
95 (%i7) abs (estimate - exact) / exact, numer;
96 (%o7) 7.5527060865060088E-11
99 A 2-dimensional integration, implemented by nested calls to @code{romberg}.
102 (%i1) load ("romberg");
103 (%o1) /usr/share/maxima/5.11.0/share/numeric/romberg.lisp
104 (%i2) g(x, y) := x*y / (x + y);
106 (%o2) g(x, y) := -----
108 (%i3) rombergtol : 1e-6;
109 (%o3) 9.9999999999999995E-7
110 (%i4) estimate : romberg (romberg (g(x, y), y, 0, x/2), x, 1, 3);
111 (%o4) 0.81930239628356
112 (%i5) assume (x > 0);
114 (%i6) integrate (integrate (g(x, y), y, 0, x/2), x, 1, 3);
118 (%o6) - 9 log(-) + 9 log(3) + ------------ + -
120 (%i7) exact : radcan (%);
121 26 log(3) - 26 log(2) - 13
122 (%o7) - --------------------------
124 (%i8) abs (estimate - exact) / exact, numer;
125 (%o8) 1.3711979871851024E-10
129 @c -----------------------------------------------------------------------------
131 @defvr {Option variable} rombergabs
132 Default value: @code{0.0}
134 The accuracy of @mref{romberg} is governed by the global variables
135 @code{rombergabs} and @mrefdot{rombergtol} @code{romberg} terminates
136 successfully when the absolute difference between successive approximations is
137 less than @code{rombergabs}, or the relative difference in successive
138 approximations is less than @code{rombergtol}. Thus when @code{rombergabs} is
139 @code{0.0} (the default) only the relative error test has any effect on
142 See also @mref{rombergit} and @mrefdot{rombergmin}
145 @c -----------------------------------------------------------------------------
147 @defvr {Option variable} rombergit
148 Default value: @code{11}
150 @mref{romberg} halves the stepsize at most @code{rombergit} times before it
151 gives up; the maximum number of function evaluations is therefore
152 @code{2^rombergit}. @code{romberg} always makes at least @mref{rombergmin}@w{}
153 iterations; this is a heuristic intended to prevent spurious termination when
154 the integrand is oscillatory.
156 See also @mref{rombergabs} and @mrefdot{rombergtol}
159 @c -----------------------------------------------------------------------------
161 @defvr {Option variable} rombergmin
162 Default value: @code{0}
164 @mref{romberg} always makes at least @code{rombergmin} iterations; this is a
165 heuristic intended to prevent spurious termination when the integrand is
168 See also @mrefcomma{rombergit} @mrefcomma{rombergabs} and @mrefdot{rombergtol}
171 @c -----------------------------------------------------------------------------
173 @defvr {Option variable} rombergtol
174 Default value: @code{1e-4}
176 The accuracy of @mref{romberg} is governed by the global variables
177 @mref{rombergabs} and @code{rombergtol}. @code{romberg} terminates successfully
178 when the absolute difference between successive approximations is less than
179 @code{rombergabs}, or the relative difference in successive approximations is
180 less than @code{rombergtol}. Thus when @code{rombergabs} is @code{0.0} (the
181 default) only the relative error test has any effect on @code{romberg}.
183 See also @mref{rombergit} and @mrefdot{rombergmin}
186 @c --- End of file romberg.de.texi ---------------------------------------------