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.
restart;
withStudentNumericalAnalysis:
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.
DE1≔ⅆⅆ t yt=yt2−t
DE1≔ⅆⅆty⁡t=y⁡t2−t
InitialValueProblemDE1, y0=0.4,t=4,method= adamsbashforth,output=solution;
−3.933
InitialValueProblemDE1, y0=0.4,t=4,method= adamsbashforth,output=solution, Error;
−3.933,2.002
The InitialValueProblem command can also return a plot of the exact and approximated solution, using the output=plot option.
InitialValueProblemDE1, y0=0.4,t=4,method=rungekutta,submethod=rk4,output=plot;
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.
InitialValueProblemDE1, y0=0.4,t=4,method=rungekutta,submethod=rk4,comparewith=euler, adamsbashforth,step2, output=plot;
InitialValueProblemDE1, y0=0.4,t=4,method=rungekutta,submethod=rk4,comparewith=euler,taylor,5, output=information;
tMaple's numeric solutionR-K 4th Ord.ErrorEulerError5th-Ord. TaylorError0.0.40.40.0.40.0.40.0.80000.18420.19070.0065400.52800.34380.17790.00631.600−0.6829−0.67320.0097280.11100.7939−0.65720.02572.400−1.355−1.3110.04412−1.1590.1959−1.3810.0263.200−1.693−1.6180.07503−2.0040.3113−1.6920.0014.−1.931−1.8190.1118−1.3510.5804−1.9310.
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. A list of commands that accept a POLYINTERP structure is found in the Glossary of Commands, under Interpolation.
data1 ≔ 0.422,1.023,3.533,2.533,4.022,6.342,5.002,8.333,6.003,9.000
data1≔0.422,1.023,3.533,2.533,4.022,6.342,5.002,8.333,6.003,9.000
Use the PolynomialInterpolation command to perform the interpolation and store all information.
p1≔PolynomialInterpolationdata1, method=newton, function=expx,independentvar=x,errorboundvar=ξ:
Extract the interpolant from the POLYINTERP structure using the Interpolant command.
Interpolantp1
0.8181719704+0.4853744777⁢x+2.028886549⁢x−0.422⁢x−3.533−1.298772557⁢x−0.422⁢x−3.533⁢x−4.022+0.4670460951⁢x−0.422⁢x−3.533⁢x−4.022⁢x−5.002
Extract the function using the Function command.
Functionp1
ⅇx
Extract the remainder term using the RemainderTerm command.
RemainderTermp1
ⅇξ⁢x−0.422⁢x−3.533⁢x−4.022⁢x−5.002⁢x−6.003120&where0.422≤ξ≤6.003
Use the Draw command to plot the basis functions from the Newton interpolation.
Drawp1,objects=BasisFunctions
Perform a cubic spline interpolation using the CubicSpline command.
p2≔CubicSplinedata1,independentvar=x:
Use the Draw command to plot the interpolating polynomial.
Drawp2
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.
M1≔Matrix4.2,2.2,0.2,1.0,5.3,2.1,0.3,3.2,6.3
M1≔4.22.20.21.05.32.10.33.26.3
Factor the matrix.
P1,L1,U1≔MatrixDecompositionM1, method=PLU
P1,L1,U1≔100010001,1000.2380952381100.071428571430.63708873391,4.22.20.204.7761904762.052380952004.978165504
Check if the matrix is strictly diagonally dominant.
IsMatrixShapeM1, strictlydiagonallydominant
true
Approximate the solution to a system of equations using the Successive Over-Relaxation method.
V1 ≔ Vector1.5,4.3,3.2
V1≔1.54.33.2
LinearSolveM1,V1,method=SOR1.25
−0.054573766920.77538756110.1166895821
Numerical Quadrature
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→sinx
f≔x↦sin⁡x
int1≔1+ⅆⅆ x fx2
int1≔1+cos⁡x2
Use the Boole method to numerically approximate the value of ∫1141+cosx2ⅆx.
Quadratureint1, x=1..14,method=boole,output=value
15.74194117
The output=plot option can be used to display a plot of the approximation.
Quadratureint1, x=1..14, method=boole,output=plot
Adaptive quadrature is also available using the adaptive=true option in the Quadrature command or the AdaptiveQuadrature command.
AdaptiveQuadratureint1,x=1..14,method=newtoncotes4
15.74186755
Use the output=information option to print a record of the adaptations performed during the approximation.
AdaptiveQuadratureint1,x=1..14,method=newtoncotes4,output=information
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 [[1], [17/4, 15/2]] 1..21/8 PASS [[2], [21/8, 17/4]] 21/8..17/4 PASS [[1], [17/4, 15/2]] 17/4..15/2 fail [15/2, 14] 17/4..47/8 PASS [[1], [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 [[1], [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≔ln1−x+cos1−x
f≔ln⁡1−x+cos⁡−1+x
Try the Bisection method.
Rootsf,x=0,1,method=bisection
0.6022644043
Try the Newton-Raphson method and use the output=plot option to display the approximation.
Rootsf,x=.4,stoppingcriterion=absolute,method=newton,output=plot
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.
IterativeFormulaTutor
See Also
Glossary of Commands, Student[NumericalAnalysis]
Return to Index for Example Worksheets
Download Help Document