Student[NumericalAnalysis] - Maple Programming Help

Student[NumericalAnalysis]

 return or plot a numerical approximation to an integral using an adaptive method

Parameters

 f - algebraic; expression in the variable x x - name; the independent variable of f a,b - numeric; the end points of the curve opts - (optional) equation(s) of the for keyword=value, where keyword is one of: boxoptions, functionoptions, iterations, method, outline, output, partition, partitionlist, partitiontype, pointoptions, refinement, showarea, showfunction, showpoints, subpartition, caption, view; the options for numerically approximating the integrand, f

Options

 • boxoptions = list
 A list of options for the plot of approximating boxes. For more information on plot options, see plot/options.
 • functionoptions = list
 A list of options for the plot of the expression f. By default, the expression is plotted as a solid red line. For more information on plot options, see plot/options.
 • iterations = posint
 The number of successive refinements in the animation. By default, the value is 6.
 • method = boole, [boole, positive], [boole, positive, posint], simpson, [simpson, positive], [simpson, positive, posint], simpson[3/8], [simpson[3/8], positive], [simpson[3/8], positive, posint], trapezoid, [trapezoid, positive], [trapezoid, positive, posint], newtoncotes[posint], [newtoncotes[posint], positive], [newtoncotes[posint], positive, posint], newtoncotes[closed, posint], or newtoncotes[open, nonnegint]
 The method of approximating the integral. By default, Simpson's rule is used.
 – boole = Boole's rule
 – simpson = Simpson's rule
 – simpson[3/8] = Simpson's 3/8 rule
 – trapezoid = trapezoid rule
 – newtoncotes[N] = Newton-Cotes method of order N
 Note: Boole's rule (which is the fourth order Newton-Cotes method) is sometimes known as Bode's rule. This is apparently due to an erroneous attribution in the literature. This command will accept either method=boole or method=bode.
 When the Newton-Cotes method is specified without either an open or closed option, the Newton-Cotes closed method is used.
 The method option sequences method=[meth, positive] and method=[meth,positive, posint], where meth is one of boole, simpson, simpson[3/8], trapezoid, or newtoncotes[N],i are only valid when adaptive is set to true.
 In the method = [meth, positive] option calling sequence, meth is the method and the 2nd list entry of type positive is the error tolerance of the approximation.
 In the method = [meth, positive, posint] option calling sequence, meth is the method, the 2nd list entry of type positive is the error tolerance of the approximation, and the 3rd list entry of type posint is the maximum number iterations to perform.
 The default tolerance is ${10}^{\mathrm{-4}}$ and the default maximum number of iterations depends on the environment variable Digits and is determined using the expression 50*max(Digits, Digits*2-4).
 • outline = true or false
 Whether the boxes as a whole are outlined. Setting this option to true provides a less cluttered image when the partition is large. By default, this is set to false.
 • output = value, sum, plot, animation, or information
 This option controls the return value of the function.
 – output=value: The value of the approximation is to be returned. Plot options are ignored if output=value. This is the default.
 – output=sum: An inert sum with the appropriate summand is returned. Plot options are ignored if output=sum.
 – output=plot: A plot, which shows the expression f and an approximation to the integral on (a, b), is displayed.
 – output=animation: An animation, which shows the expression f and approximations using a sequence of partitions, each of which is a refinement of its predecessor, is displayed.
 – output=information: Information relevant to the numerical integration is printed in the interface.  Plot options are ignored if output=information.
 • partition = posint, list(algebraic), random[algebraic], or algebraic
 The partition option controls the partitioning of the interval (a, b).
 By default, the interval is divided into 10 equally spaced subintervals.
 A positive integer value divides the interval into that number of equally spaced subintervals.
 A list of algebraic values is assumed to be the partition. If the end points are not included in the partition, they are added. The values are assumed to be sorted in ascending order.
 The value random indexed by an algebraic value c creates a random partition with the width of each subinterval chosen in the closed interval $\left[\frac{c}{2},c\right]$. The parameter c must evaluate to a positive value.
 An arbitrary algebraic expression given as the value of this option is assumed to be a positive integer and is useful only if the output option is sum.
 • partitionlist = list(posint)
 A list of partitions to use in approximating the integral of f. Each positive integer value divides the interval into that number of equally spaced subintervals.  This option is ignored unless output=information.
 • partitiontype = normal or subintervals
 The partitiontype option controls the type of partitioning used in solving the approximation. This option only applies to Newton-Cotes methods, which include the Trapezoid rule, Simpson's rule, Simpson's 3/8 rule, and Boole's rule.
 – partitiontype=normal: Each end of a partition is used as one single evaluation point in approximating the integral. As a result, the number of partitions must be a multiple of a certain integer depending on the method: a multiple of 2 when using Simpson's rule, a multiple of 3 when using Simpson's 3/8 rule, a multiple of 4 when using Boole's rule, and a multiple of n when using a Newton-Cotes[n] rule. This option does not work with partition=random[c].
 – partitiontype=subintervals: Each partition is used as a subinterval instead, with each subinterval divided into the appropriate number of partitions for each method. There is no limit on the partition number when using this option. This is the default.
 • pointoptions = list
 A list of options for the points on the plot.  This option is ignored if one of the Newton-Cotes methods, which include the Trapezoid rule, Simpson's rule, Simpson's 3/8 rule, and Boole's rule, is used.  This option is also ignored unless output=plot. For more information on plot options, see plot/options.
 • refinement = halve, random, or numeric in (0,1)
 In an animation, the refinement controls how an interval is subpartitioned. The default is halve.
 The value halve indicates that the interval is subdivided into two equal subintervals.
 The value random indicates that the interval is randomly subdivided. The random value is chosen from the average of two uniform distributions.
 A numeric value c must be in the open interval $0,1$ which indicates that the closed interval [p,q] is broken into the intervals $\left[p,p+c\left(q-p\right)\right]$ and $\left[p+c\left(q-p\right),q\right]$.
 • showarea = true or false
 Whether the approximation of the integral of f is displayed on the plot. By default, this is set to true.
 • showfunction = true or false
 Whether the expression f is plotted. By default, this is set to true.
 • showpoints = true or false
 Whether the points at which the function f is evaluated at to obtain the height of the corresponding box are shown. This option is ignored if one of the Newton-Cotes methods, which include the Trapezoid rule, Simpson's rule, Simpson's 3/8 rule, and Boole's rule, is used.  This option is also ignored unless output=plot.
 • subpartition = all, width, or area
 In an animation, subpartition controls which intervals are subpartitioned each iteration. The default is all.
 The value all indicates that every subinterval is subpartitioned.
 The value width indicates that the interval with greatest width is subpartitioned. If there is more than one interval with largest width, the leftmost is chosen.
 The value area indicates that the interval with greatest area is subpartitioned. If there is more than one interval with largest area, the leftmost is chosen.
 • caption = anything
 A caption for the plot. The default caption depends on methods used to find the approximation. For more information about specifying a caption, see plot/typesetting.
 • view = [realcons..realcons, realcons..realcons]
 The plot view of the plot when output=plot.  See plot/options for more information.

Description

 • The AdaptiveQuadrature command returns a numerical approximation to the integral of f from a to b, using the specified adaptive method. Note that this command is a shortcut for calling the Quadrature command with the adaptive=true option.

Examples

 > $\mathrm{with}\left({\mathrm{Student}}_{\mathrm{NumericalAnalysis}}\right):$
 > $f≔\sqrt{1+{\mathrm{cos}\left(x\right)}^{2}}:$
 > $a≔0:$
 > $b≔48:$

The command to numerically approximate the integral of the expression above using Simpson's rule is

 > $\mathrm{AdaptiveQuadrature}\left(f,x=a..b,\mathrm{method}=\mathrm{simpson},\mathrm{partition}=4,\mathrm{output}=\mathrm{value}\right)$
 ${58.47048191}$ (1)

The command to create a plot of the above approximation is

 > $\mathrm{AdaptiveQuadrature}\left(f,x=a..b,\mathrm{method}=\mathrm{simpson},\mathrm{partition}=4,\mathrm{output}=\mathrm{plot}\right)$ > $f≔\frac{x}{\sqrt{{x}^{2}-4}}:$
 > $a≔3:$
 > $b≔3.5:$

The command to numerically approximate the definite integral of the above expression using the trapezoid rule and to print other relevant information concerning the approximation in the interface is

 > $\mathrm{AdaptiveQuadrature}\left(f,x=a..b,\mathrm{method}=\mathrm{trapezoid},\mathrm{output}=\mathrm{information}\right)$
 INTEGRAL: Int(x/(x^2-4)^(1/2),x=3..3.5) = 0.636213346       APPROXIMATION METHOD: Adaptive Trapezoidal Rule ---------------------------------- INFORMATION TABLE ----------------------------------     Approximate Value         Absolute Error         Relative Error          0.636258036             4.46897e-05          0.007024 % ---------------------------------- ITERATION HISTORY ---------------------------------------    Interval           Status         Present Stack  3.0000..3.5000        fail           EMPTY  3.0000..3.2500        fail           [3.2500, 3.5000]  3.0000..3.1250        fail           [, [3.1250, 3.2500]]  3.0000..3.0625        PASS           [, [3.0625, 3.1250]]  3.0625..3.1250        PASS           [, [3.1250, 3.2500]]  3.1250..3.2500        PASS           [3.2500, 3.5000]  3.2500..3.5000        fail           EMPTY  3.2500..3.3750        PASS           [3.3750, 3.5000]  3.3750..3.5000        PASS           EMPTY -------------------------------------------------------------------------------------------- Number of Function Evaluations:     11

Now use an adaptive Newton-Cotes order 1 approximation with a specific tolerance on the same expression

 > $\mathrm{AdaptiveQuadrature}\left(f,3..3.5,\mathrm{adaptive}=\mathrm{true},\mathrm{method}=\left[{\mathrm{newtoncotes}}_{1},{10}^{-4}\right],\mathrm{output}=\mathrm{information}\right)$
 INTEGRAL: Int(x/(x^2-4)^(1/2),x=3..3.5) = 0.636213346       APPROXIMATION METHOD: Adaptive Trapezoidal Rule ---------------------------------- INFORMATION TABLE ----------------------------------     Approximate Value         Absolute Error         Relative Error          0.636258036             4.46897e-05          0.007024 % ---------------------------------- ITERATION HISTORY ---------------------------------------    Interval           Status         Present Stack  3.0000..3.5000        fail           EMPTY  3.0000..3.2500        fail           [3.2500, 3.5000]  3.0000..3.1250        fail           [, [3.1250, 3.2500]]  3.0000..3.0625        PASS           [, [3.0625, 3.1250]]  3.0625..3.1250        PASS           [, [3.1250, 3.2500]]  3.1250..3.2500        PASS           [3.2500, 3.5000]  3.2500..3.5000        fail           EMPTY  3.2500..3.3750        PASS           [3.3750, 3.5000]  3.3750..3.5000        PASS           EMPTY -------------------------------------------------------------------------------------------- Number of Function Evaluations:     11