2 * Functions and Variables for romberg::
5 @node Functions and Variables for romberg, , Package romberg, Package romberg
6 @section Functions and Variables for romberg
8 @anchor{romberg_function}
9 @deffn {Function} romberg @
10 @fname{romberg} (@var{expr}, @var{x}, @var{a}, @var{b}) @
11 @fname{romberg} (@var{F}, @var{a}, @var{b})
13 Computes a numerical integration by Romberg's method.
15 @code{romberg(@var{expr}, @var{x}, @var{a}, @var{b})}
16 returns an estimate of the integral @code{integrate(@var{expr}, @var{x}, @var{a}, @var{b})}.
17 @var{expr} must be an expression which evaluates to a floating point value
18 when @var{x} is bound to a floating point value.
20 @code{romberg(@var{F}, @var{a}, @var{b})}
21 returns an estimate of the integral @code{integrate(@var{F}(x), x, @var{a}, @var{b})}
22 where @code{x} represents the unnamed, sole argument of @var{F};
23 the actual argument is not named @code{x}.
24 @var{F} must be a Maxima or Lisp function which returns a floating point value
25 when the argument is a floating point value.
26 @var{F} may name a translated or compiled Maxima function.
28 The accuracy of @code{romberg} is governed by the global variables
29 @code{rombergabs} and @code{rombergtol}.
30 @code{romberg} terminates successfully when
31 the absolute difference between successive approximations is less than @code{rombergabs},
32 or the relative difference in successive approximations is less than @code{rombergtol}.
33 Thus when @code{rombergabs} is 0.0 (the default)
34 only the relative error test has any effect on @code{romberg}.
36 @code{romberg} halves the stepsize at most @code{rombergit} times before it gives up;
37 the maximum number of function evaluations is therefore @code{2^rombergit}.
38 If the error criterion established by @code{rombergabs} and @code{rombergtol}
39 is not satisfied, @code{romberg} prints an error message.
40 @code{romberg} always makes at least @code{rombergmin} iterations;
41 this is a heuristic intended to prevent spurious termination when the integrand is oscillatory.
43 @code{romberg} repeatedly evaluates the integrand after binding the variable
44 of integration to a specific value (and not before).
45 This evaluation policy makes it possible to nest calls to @code{romberg},
46 to compute multidimensional integrals.
47 However, the error calculations do not take the errors of nested integrations
48 into account, so errors may be underestimated.
49 Also, methods devised especially for multidimensional problems may yield
50 the same accuracy with fewer function evaluations.
52 See also @mref{Introduction to QUADPACK}, a collection of numerical integration functions.
56 A 1-dimensional integration.
58 @c f(x) := 1/((x - 1)^2 + 1/100) + 1/((x - 2)^2 + 1/1000)
59 @c + 1/((x - 3)^2 + 1/200);
62 @c estimate : romberg (f(x), x, -5, 5);
63 @c exact : integrate (f(x), x, -5, 5);
64 @c abs (estimate - exact) / exact, numer;
68 (%i1) f(x) := 1/((x - 1)^2 + 1/100) + 1/((x - 2)^2 + 1/1000)
69 + 1/((x - 3)^2 + 1/200);
71 (%o1) f(x) := -------------- + --------------- + --------------
73 (x - 1) + --- (x - 2) + ---- (x - 3) + ---
77 (%i2) rombergtol : 1e-6;
78 (%o2) 9.999999999999999e-7
85 (%i4) estimate : romberg (f(x), x, -5, 5);
86 (%o4) 173.6730736617464
89 (%i5) exact : integrate (f(x), x, -5, 5);
91 (%o5) 10 atan(7 10 ) + 10 atan(3 10 )
93 + 5 2 atan(5 2 ) + 5 2 atan(5 2 ) + 10 atan(60)
97 (%i6) abs (estimate - exact) / exact, numer;
98 (%o6) 7.552722451569877e-11
102 A 2-dimensional integration, implemented by nested calls to @code{romberg}.
104 @c g(x, y) := x*y / (x + y);
105 @c rombergtol : 1e-6;
106 @c estimate : romberg (romberg (g(x, y), y, 0, x/2), x, 1, 3);
108 @c integrate (integrate (g(x, y), y, 0, x/2), x, 1, 3);
109 @c exact : radcan (%);
110 @c abs (estimate - exact) / exact, numer;
114 (%i1) g(x, y) := x*y / (x + y);
116 (%o1) g(x, y) := -----
120 (%i2) rombergtol : 1e-6;
121 (%o2) 9.999999999999999e-7
124 (%i3) estimate : romberg (romberg (g(x, y), y, 0, x/2), x, 1, 3);
125 (%o3) 0.8193023962835647
128 (%i4) assume (x > 0);
132 (%i5) integrate (integrate (g(x, y), y, 0, x/2), x, 1, 3);
136 (%o5) (- 9 log(-)) + 9 log(3) + ------------ + -
140 (%i6) exact : radcan (%);
141 26 log(3) - 26 log(2) - 13
142 (%o6) - --------------------------
146 (%i7) abs (estimate - exact) / exact, numer;
147 (%o7) 1.371197987185102e-10
151 @opencatbox{Categories:}
152 @category{Package romberg}
153 @category{Numerical methods}
159 @defvr {Option variable} rombergabs
162 The accuracy of @code{romberg} is governed by the global variables
163 @code{rombergabs} and @code{rombergtol}.
164 @code{romberg} terminates successfully when
165 the absolute difference between successive approximations is less than @code{rombergabs},
166 or the relative difference in successive approximations is less than @code{rombergtol}.
167 Thus when @code{rombergabs} is 0.0 (the default)
168 only the relative error test has any effect on @code{romberg}.
170 See also @mref{rombergit} and @mref{rombergmin}.
172 @opencatbox{Categories:}
173 @category{Package romberg}
179 @defvr {Option variable} rombergit
182 @code{romberg} halves the stepsize at most @code{rombergit} times before it gives up;
183 the maximum number of function evaluations is therefore @code{2^rombergit}.
184 @code{romberg} always makes at least @code{rombergmin} iterations;
185 this is a heuristic intended to prevent spurious termination when the integrand is oscillatory.
187 See also @mref{rombergabs} and @mref{rombergtol}.
189 @opencatbox{Categories:}
190 @category{Package romberg}
196 @defvr {Option variable} rombergmin
199 @code{romberg} always makes at least @code{rombergmin} iterations;
200 this is a heuristic intended to prevent spurious termination when the integrand is oscillatory.
202 See also @mref{rombergit}, @mref{rombergabs}, and @mref{rombergtol}.
204 @opencatbox{Categories:}
205 @category{Package romberg}
211 @defvr {Option variable} rombergtol
214 The accuracy of @code{romberg} is governed by the global variables
215 @code{rombergabs} and @code{rombergtol}.
216 @code{romberg} terminates successfully when
217 the absolute difference between successive approximations is less than @code{rombergabs},
218 or the relative difference in successive approximations is less than @code{rombergtol}.
219 Thus when @code{rombergabs} is 0.0 (the default)
220 only the relative error test has any effect on @code{romberg}.
222 See also @mref{rombergit} and @mref{rombergmin}.
224 @opencatbox{Categories:}
225 @category{Package romberg}