 Student Numerical Analysis - Maple Help

The Student[NumericalAnalysis] Package

The Student[NumericalAnalysis] package contains commands that can be used to learn and understand numerical analysis concepts. The areas of numerical analysis that the package covers are: initial-value problems, interpolation, numerical linear algebra, numerical quadrature, and root finding. This worksheet demonstrates how to use some of the commands and how to launch the interactive tutors. Getting Started

While any command in the package can be referred to using the long form, for example, Student[NumericalAnalysis][Euler], it is often easier to load the package and then use the short form command names.

 > $\mathrm{restart};$
 > $\mathrm{with}\left(\mathrm{Student}\left[\mathrm{NumericalAnalysis}\right]\right):$ Initial-Value Problems

The Student[NumericalAnalysis] package contains several commands that can numerically approximate the solution to an initial-value problem. A standard suite of approximation methods are available, including the Adams-Bashforth explicit, Adams-Moulton implicit, Adams-Bashforth-Moulton predictor-corrector, Euler, Runge-Kutta, and Taylor methods. In particular, difference formulae of various orders are available from the Adams and Runge-Kutta families of methods.

 >
 ${\mathrm{DE1}}{≔}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{y}{}\left({t}\right){=}{{y}{}\left({t}\right)}^{{2}}{-}{t}$ (2.1)
 >
 ${-3.933}$ (2.2)
 >
 ${-3.933}{,}{2.002}$ (2.3)

The InitialValueProblem command can also return a plot of the exact and approximated solution, using the output=plot option.

 > The comparewith option allows the student to compare different approximation methods and the exact solution. The comparewith option can be used with the output=plot and output=information options.

 > >
 $\left[\begin{array}{cccccccc}t& \left[\mathrm{Maple\text{'}s numeric solution}\right]& \left[\mathrm{R-K 4th Ord.}\right]& \left[\mathrm{Error}\right]& \left[\mathrm{Euler}\right]& \left[\mathrm{Error}\right]& \left[\mathrm{5th-Ord. Taylor}\right]& \left[\mathrm{Error}\right]\\ 0.& 0.4& 0.4& 0.& 0.4& 0.& 0.4& 0.\\ 0.8000& 0.1842& 0.1907& 0.006540& 0.5280& 0.3438& 0.1779& 0.0063\\ 1.600& -0.6829& -0.6732& 0.009728& 0.1110& 0.7939& -0.6572& 0.0257\\ 2.400& -1.355& -1.311& 0.04412& -1.159& 0.1959& -1.381& 0.026\\ 3.200& -1.693& -1.618& 0.07503& -2.004& 0.3113& -1.692& 0.001\\ 4.& -1.931& -1.819& 0.1118& -1.351& 0.5804& -1.931& 0.\end{array}\right]$ (2.4) Interpolation

The Student[NumericalAnalysis] package contains several commands that allow students to perform polynomial and cubic spline interpolations on data points. The available methods of interpolation include Lagrange, Newton, Hermite, Neville, and cubic spline interpolation. The interpolation is computed by either the PolynomialInterpolation command or the CubicSpline command. These commands return a POLYINTERP data structure which can then be passed to different Student[NumericalAnalysis] commands to retrieve information.

 >
 ${\mathrm{data1}}{≔}\left[\left[{0.422}{,}{1.023}\right]{,}\left[{3.533}{,}{2.533}\right]{,}\left[{4.022}{,}{6.342}\right]{,}\left[{5.002}{,}{8.333}\right]{,}\left[{6.003}{,}{9.000}\right]\right]$ (3.1)

Use the PolynomialInterpolation command to perform the interpolation and store all information.

 >

Extract the interpolant from the POLYINTERP structure using the Interpolant command.

 > $\mathrm{Interpolant}\left(\mathrm{p1}\right)$
 ${0.8181719704}{+}{0.4853744777}{x}{+}{2.028886549}\left({x}{-}{0.422}\right)\left({x}{-}{3.533}\right){-}{1.298772557}\left({x}{-}{0.422}\right)\left({x}{-}{3.533}\right)\left({x}{-}{4.022}\right){+}{0.4670460951}\left({x}{-}{0.422}\right)\left({x}{-}{3.533}\right)\left({x}{-}{4.022}\right)\left({x}{-}{5.002}\right)$ (3.2)

Extract the function using the Function command.

 > $\mathrm{Function}\left(\mathrm{p1}\right)$
 ${{ⅇ}}^{{x}}$ (3.3)

Extract the remainder term using the RemainderTerm command.

 > $\mathrm{RemainderTerm}\left(\mathrm{p1}\right)$
 $\left(\frac{{{ⅇ}}^{{\mathrm{\xi }}}\left({x}{-}{0.422}\right)\left({x}{-}{3.533}\right)\left({x}{-}{4.022}\right)\left({x}{-}{5.002}\right)\left({x}{-}{6.003}\right)}{{120}}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{&where}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\left\{{0.422}{\le }{\mathrm{\xi }}{\le }{6.003}\right\}$ (3.4)

Use the Draw command to plot the basis functions from the Newton interpolation.

 > $\mathrm{Draw}\left(\mathrm{p1},\mathrm{objects}=\mathrm{BasisFunctions}\right)$ Perform a cubic spline interpolation using the CubicSpline command.

 > $\mathrm{p2}≔\mathrm{CubicSpline}\left(\mathrm{data1},\mathrm{independentvar}=x\right):$

Use the Draw command to plot the interpolating polynomial.

 > $\mathrm{Draw}\left(\mathrm{p2}\right)$  Numerical Linear Algebra

The Student[NumericalAnalysis] package contains several commands that allow students to explore numerical linear algebra. Matrix decomposition and iterative approximation methods are the two main focuses of the numerical linear algebra commands in the Student[NumericalAnalysis] package. The available iterative approximation techniques include the Gauss-Seidel, Jacobi, and Successive Over-Relaxation methods.

 > $\mathrm{M1}≔\mathrm{Matrix}\left(\left[\left[4.2,2.2,0.2\right],\left[1.0,5.3,2.1\right],\left[0.3,3.2,6.3\right]\right]\right)$
 $\left[\begin{array}{ccc}4.2& 2.2& 0.2\\ 1.0& 5.3& 2.1\\ 0.3& 3.2& 6.3\end{array}\right]$ (4.1)

Factor the matrix.

 >
 ${\mathrm{P1}}{,}{\mathrm{L1}}{,}{\mathrm{U1}}{≔}\left[\begin{array}{ccc}{1}& {0}& {0}\\ {0}& {1}& {0}\\ {0}& {0}& {1}\end{array}\right]{,}\left[\begin{array}{ccc}{1}& {0}& {0}\\ {0.2380952381}& {1}& {0}\\ {0.07142857143}& {0.6370887339}& {1}\end{array}\right]{,}\left[\begin{array}{ccc}{4.2}& {2.2}& {0.2}\\ {0}& {4.776190476}& {2.052380952}\\ {0}& {0}& {4.978165504}\end{array}\right]$ (4.2)

Check if the matrix is strictly diagonally dominant.

 >
 ${\mathrm{true}}$ (4.3)

Approximate the solution to a system of equations using the Successive Over-Relaxation method.

 >
 $\left[\begin{array}{c}1.5\\ 4.3\\ 3.2\end{array}\right]$ (4.4)
 > $\mathrm{LinearSolve}\left(\mathrm{M1},\mathrm{V1},\mathrm{method}=\mathrm{SOR}\left(1.25\right)\right)$
 $\left[\begin{array}{c}-0.05457376692\\ 0.7753875611\\ 0.1166895821\end{array}\right]$ (4.5) The Student[NumericalAnalysis] package contains several commands that allow students to numerically approximate integrals using different methods. The available quadrature methods include the complete family of Newton-Cotes formulae (open or closed, with a user-specified order), Gaussian Quadrature, and Romberg Integration. Some of these methods can be used with the adaptive=true option in the Quadrature command or with the AdaptiveQuadrature command. The results of the approximate integration can be returned as a sum, value, plot, animation, or as printed information about the computation.

 > $f≔x\to \mathrm{sin}\left(x\right)$
 ${f}{≔}{x}{↦}{\mathrm{sin}}{}\left({x}\right)$ (5.1)
 >
 ${\mathrm{int1}}{≔}\sqrt{{1}{+}{{\mathrm{cos}}{}\left({x}\right)}^{{2}}}$ (5.2)

Use the Boole method to numerically approximate the value of ${\int }_{1}^{14}\sqrt{1+\mathrm{cos}{\left(x\right)}^{2}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}ⅆx.$

 >
 ${15.74194117}$ (5.3)

The output=plot option can be used to display a plot of the approximation.

 > > $\mathrm{AdaptiveQuadrature}\left(\mathrm{int1},x=1..14,\mathrm{method}=\mathrm{newtoncotes}\left[4\right]\right)$
 ${15.74186755}$ (5.4)

Use the output=information option to print a record of the adaptations performed during the approximation.

 > $\mathrm{AdaptiveQuadrature}\left(\mathrm{int1},x=1..14,\mathrm{method}=\mathrm{newtoncotes}\left[4\right],\mathrm{output}=\mathrm{information}\right)$
 INTEGRAL: Int((1+cos(x)^2)^(1/2),x=1..14) = 15.7418533        APPROXIMATION METHOD: Adaptive Bode's Rule ---------------------------------- INFORMATION TABLE ----------------------------------     Approximate Value         Absolute Error         Relative Error           15.7418676               1.426e-05         9.059e-05 % ---------------------------------- ITERATION HISTORY ---------------------------------------    Interval           Status         Present Stack       1..14            fail           EMPTY       1..15/2          fail           [15/2, 14]       1..17/4          fail           [, [17/4, 15/2]]       1..21/8          PASS           [, [21/8, 17/4]]    21/8..17/4          PASS           [, [17/4, 15/2]]    17/4..15/2          fail           [15/2, 14]    17/4..47/8          PASS           [, [47/8, 15/2]]    47/8..15/2          PASS           [15/2, 14]    15/2..14            fail           EMPTY    15/2..43/4          fail           [43/4, 14]    15/2..73/8          PASS           [, [73/8, 43/4]]    73/8..43/4          PASS           [43/4, 14]    43/4..14            fail           EMPTY    43/4..99/8          PASS           [99/8, 14]    99/8..14            PASS           EMPTY -------------------------------------------------------------------------------------------- Number of Function Evaluations:     65 Root Finding

The Student[NumericalAnalysis] package contains commands that allow students to numerically approximate the roots of an expression. A suite of basic numerical root-finding methods are available, including Newton-Raphson, Modified Newton-Raphson, Bisection, Secant, Fixed-Point Iteration, False-Position, and Steffensen.

 > $f≔\mathrm{ln}\left(1-x\right)+\mathrm{cos}\left(1-x\right)$
 ${f}{≔}{\mathrm{ln}}{}\left({1}{-}{x}\right){+}{\mathrm{cos}}{}\left({-}{1}{+}{x}\right)$ (6.1)

Try the Bisection method.

 > $\mathrm{Roots}\left(f,x=\left[0,1\right],\mathrm{method}=\mathrm{bisection}\right)$
 ${0.6022644043}$ (6.2)

Try the Newton-Raphson method and use the output=plot option to display the approximation.

 > $\mathrm{Roots}\left(f,x=.4,\mathrm{stoppingcriterion}=\mathrm{absolute},\mathrm{method}=\mathrm{newton},\mathrm{output}=\mathrm{plot}\right)$  Tutors

The Student[NumericalAnalysis] package contains four interactive tutors to assist students with solving numerical analysis problems: EulerTutor, InitialValueProblemTutor, IterativeFormulaTutor, and MatrixDecompositionTutor. The tutors can be accessed via the menu path Tools > Tutors > Numerical Analysis or by invoking the tutor in a worksheet as shown below.

 > $\mathrm{IterativeFormulaTutor}\left(\right)$ See Also