Student[NumericalAnalysis] - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Education : Student Package : Numerical Analysis : Visualization : Student/NumericalAnalysis/Roots

Student[NumericalAnalysis]

 Roots
 numerically approximate the real roots of an expression using an iterative method

 Calling Sequence Roots(f, x=[a, b], opts) Roots(f, [a,b], opts) Roots(f, x=a, opts) Roots(f, a, opts)

Parameters

 f - algebraic; expression in the variable x representing a continuous function x - name; the independent variable of f a - numeric; in the first two calling sequences, one of two initial approximates to the root; in the remaining calling sequences, the initial approximate root b - numeric; in the first two calling sequences, one of two initial approximates to the root opts - (optional) equation(s) of the form keyword=value, where keyword is one of fixedpointiterator, functionoptions, lineoptions, maxiterations, method, output, pointoptions, showfunction, showlines, showpoints, showverticallines, stoppingcriterion, tickmarks, caption, tolerance, verticallineoptions, view; the options for approximating the roots of f

Options

 • fixedpointiterator = algebraic (optional)
 Can only be specified if method = steffensen or method = fixedpointiteration.
 The expression on the right-hand side will be used to generate the fixed-point iteration sequence. If this option is specified, the first argument, f, must be omitted. See the method option under method = fixedpointiteration for more details.
 • functionoptions = list
 A list of options for the plot of the expression f. By default, f is plotted as a solid red line.
 • lineoptions = list
 A list of options for the lines on the plot. By default the lines are solid blue for the Newton-Raphson, Modified Newton-Raphson, Secant, Steffensen, and False Position methods and dotted blue for the Bisection and Fixed-Point Iteration methods.
 • maxiterations = posint
 The maximum number of iterations to perform. The default value of maxiterations depends on which type of output is chosen:
 – output = value: default maxiterations = 100
 – output = sequence: default maxiterations = 10
 – output = information: default maxiterations = 10
 – output = plot: default maxiterations = 5
 – output = animation: default maxiterations = 10
 • method = newton, modifiednewton, bisection, secant, fixedpointiteration, steffensen, or falseposition
 The method used to approximate the root(s) of f numerically.
 – newton: Newton-Raphson Method
 This method requires one initial approximate.
 – modifiednewton: Modified Newton-Raphson Method
 This method requires one initial approximate.
 – bisection: Bisection Method
 This method requires a pair of initial approximates.
 – secant: Secant Method
 This method requires a pair of initial approximates.
 – fixedpointiteration: Fixed-Point Iteration Method
 This method requires one initial approximate.
 This method first converts the problem of finding a root to the equation $f\left(x\right)=0$ to a problem of finding a fixed point for the function $g\left(x\right)$, where $g\left(x\right)=x-f\left(x\right)$ and $f\left(x\right)$ is specified by f and x.
 • The user can specify a custom iterator function $g\left(x\right)$ by omitting the first argument f and supplying the fixedpointiterator = g option. The right-hand side expression g specifies a function $g\left(x\right)$, and this procedure will aim to find a root to $f\left(x\right)$ = $x-g\left(x\right)=0$ by way of solving the fixed-point problem $g\left(x\right)=x$.
 When output = plot or output = animation is specified, both the function $f\left(x\right)$ and the fixed-point iterator function $g\left(x\right)$ will be plotted and correspondingly labeled.
 The tolerance option, when stoppingcriterion = function_value, applies to the function $f\left(x\right)$ in the root-finding form of the problem.
 The information in the preceding paragraphs applies to Steffensen's method as well.
 – steffensen: Steffensen's Method
 This method requires one initial approximate.
 See the fixed-point iteration method above (fixedpointiteration) for important information that also applies to this method.
 – falseposition: Method of False Position
 This method requires a pair of initial approximates.
 By default, the Newton-Raphson Method is used.
 • output = value, sequence, plot, animation, or information
 The return value of the function. The default is value.
 – output = value returns the final numerical approximation of the root.
 – output = sequence returns an expression sequence ${p}_{k}$, $k$=$0..n$, where, depending on the method, either form successive intervals that bracket the exact root or a sequence of successively more accurate approximate roots.
 – output = plot returns a plot of f with each iterative approximation shown and the relevant information about the numerical approximation displayed in the caption of the plot.
 – output = animation returns an animation showing the iterations of the root approximation process.
 – output = information returns detailed information about the iterative approximations of the root of f.
 • plotoptions = list
 The final plot options when output = plot or output = animation.
 • pointoptions = list
 A list of options for the points on the plot. By default, the points are plotted as green circles.
 • showfunction = truefalse
 Whether to display f on the plot or not.  By default, this option is set to true.
 • showlines = truefalse
 Whether to display lines that accentuate each approximate iteration when output = plot. This option is effective with every method except for the Modified Newton-Raphson method. By default, this option is set to true.  To control the vertical lines, see the showverticallines and verticallineoptions options.
 • showpoints = truefalse
 Whether to display the points at each approximate iteration on the plot when output = plot. By default, this option is set to true.
 • showverticallines = truefalse
 Whether to display the vertical lines at each iterative approximation on the plot when output = plot.  This option is only effective when method is one of: newton, modifiednewton, secant, or falseposition. By default this option is set to true.
 • stoppingcriterion = relative, absolute, or function_value
 The criterion that the approximations must meet before discontinuing the iterations. The following describes each criterion:
 – relative : $\frac{\left|{p}_{n}-{p}_{n-1}\right|}{\left|{p}_{n}\right|}$ < tolerance
 – absolute : $\left|{p}_{n}-{p}_{n-1}\right|$ < tolerance
 – function_value : $\left|f\left({p}_{n}\right)\right|$ < tolerance
 By default, stoppingcriterion = relative.
 • tickmarks = list
 The tickmarks when output = plot or output = animation. By default, tickmarks are placed at the initial and final approximations with the labels ${p}_{0}$ (or a and b for two initial approximates) and ${p}_{n}$, where $n$ is the total number of iterations used to reach the final approximation. See plot/tickmarks for more detail on specifying tickmarks.
 • caption = string
 A caption for the plot. The default caption contains general information concerning the approximation. For more information about specifying a caption , see plot/typesetting.
 • tolerance = positive
 The error tolerance of the approximation. The default value is $\frac{1}{10000}$.
 • verticallineoptions = list
 A list of options for the vertical lines on the plot. By default, the lines are dashed and blue.
 • view = [realcons..realcons, realcons..realcons]
 The plot view of the plot when output = plot.  See plot/options for more information.

Description

 • The Roots command numerically approximates the roots of an algebraic function, f, using the specified method and returns the specified outputs.
 • Given an expression f and an initial approximate a or a pair of initial approximates [a, b], the Roots command computes a sequence ${p}_{k}$, $k$=$0..n$, of approximations to a root of f, where $n$ is the number of iterations taken to reach a stopping criterion.
 • See method in the Options section to see which methods require one initial approximate (and hence the last two calling sequences) and which methods require a pair of initial approximates (and hence the first two calling sequences).
 • If method = fixedpointiteration or method = steffensen is specified, the first argument f may be substituted with an option of the form fixedpointiterator = fpexpr. See method = fixedpointiteration in the Options section for details.

Notes

 • Both Newton's method and the secant method have the limitation that they may produce a divergent sequence of approximates if the initial approximates a and b are not sufficiently close to the root.

Examples

 > $\mathrm{with}\left(\mathrm{Student}[\mathrm{NumericalAnalysis}]\right):$
 > $f≔{x}^{3}-7{x}^{2}+14x-6$
 ${f}{≔}{{x}}^{{3}}{-}{7}{}{{x}}^{{2}}{+}{14}{}{x}{-}{6}$ (1)
 > $\mathrm{Roots}\left(f,x=3.2,\mathrm{tolerance}={10}^{-2}\right)$
 ${3.416190743}$ (2)
 > $\mathrm{Roots}\left(f,x=\left[2.7,3.2\right],\mathrm{method}=\mathrm{bisection},\mathrm{tolerance}={10}^{-2},\mathrm{output}=\mathrm{information}\right)$
 $\left[\begin{array}{cccccc}{n}& {{a}}_{{n}}& {{b}}_{{n}}& {{p}}_{{n}}& {f}{}\left({{p}}_{{n}}\right)& {\mathrm{relative error}}\\ {1}& {2.7}& {3.2}& {2.950000000}& {0.054875000}& {0.08474576271}\\ {2}& {2.950000000}& {3.2}& {3.075000000}& {-}{0.063328125}& {0.04065040650}\\ {3}& {2.950000000}& {3.075000000}& {3.012500000}& {-}{0.012185547}& {0.02074688797}\\ {4}& {2.950000000}& {3.012500000}& {2.981250000}& {0.019446526}& {0.01048218029}\\ {5}& {2.981250000}& {3.012500000}& {2.996875000}& {0.003144514}& {0.005213764338}\end{array}\right]$ (3)
 > $f≔{x}^{2}-3x-2:$
 > $\mathrm{Roots}\left(f,x=1,\mathrm{output}=\mathrm{sequence}\right)$
 ${1.}{,}{-}{3.000000000}{,}{-}{1.222222222}{,}{-}{0.6417233560}{,}{-}{0.5630533137}{,}{-}{0.5615533585}{,}{-}{0.5615528128}$ (4)
 > $\mathrm{Roots}\left(f,x=0.3,\mathrm{method}=\mathrm{modifiednewton},\mathrm{output}=\mathrm{plot},\mathrm{stoppingcriterion}=\mathrm{absolute}\right)$ > $\mathrm{Roots}\left(f,x=0.3,\mathrm{method}=\mathrm{modifiednewton},\mathrm{output}=\mathrm{plot},\mathrm{stoppingcriterion}=\mathrm{absolute},\mathrm{verticallineoptions}=\left[\mathrm{color}=\mathrm{gold},\mathrm{linestyle}=\mathrm{dash}\right]\right)$ > $\mathrm{Roots}\left(f,x=\left[1.3,5\right],\mathrm{method}=\mathrm{secant},\mathrm{output}=\mathrm{animation},\mathrm{stoppingcriterion}=\mathrm{function_value},\mathrm{tickmarks}=\left[5,5\right]\right)$ 