1. Home
  2. Explore
  3. Mathematics
  4. Numerical Methods in Maple

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Numerical Methods in Maple

Numerical Differential Equations in Maple

Numerical Differential-Equation Capabilities

Maple provides numerical tools for solving, evaluating, visualizing, and analyzing several classes of differential-equation problems:

  • Initial value problems (IVPs) for ordinary differential equations.

  • Boundary value problems (BVPs) for ordinary differential equations.

  • Delay differential equations (DDEs).

  • Differential-algebraic equations (DAEs), including higher-index systems.

  • Partial differential equations (PDEs).

  • Eigenvalue and eigenfunction problems.

  • Parameterized differential equations and parameter optimization.

  • Event-driven simulations and discrete state changes.

  • High-precision and compiled numerical computations.

For ordinary differential equations and related univariate problems, the primary command is dsolve with the numeric option. Rather than attempting to derive an exact formula, Maple constructs a numerical solution procedure that can later be evaluated at requested points.

A typical workflow is:

  1. Define the differential equation or system.

  2. Specify initial or boundary conditions.

  3. Request a numerical solution.

  4. Evaluate the solution at selected points.

  5. Plot or otherwise analyze the result.


Initial Value Problems

An initial value problem specifies the values of the dependent variables and, when necessary, their derivatives at one independent-variable point.

For example, a harmonic oscillator may be specified with initial conditions such as

y(0)=1,y′(0)=0.y(0)=1,\qquad y'(0)=0.y(0)=1,y′(0)=0.

A numerical solution procedure can then be evaluated at any requested time. The result is computed when needed rather than necessarily being computed over the entire interval in advance.

Numerical Solution Procedures

A numerical solution procedure acts as a computation engine:

  • A requested value causes Maple to integrate far enough to obtain that value.

  • Previously computed values can be reused.

  • Repeated requests near the most recently computed point are generally efficient.

  • The solution can be passed to plotting commands such as odeplot.

A solution procedure can therefore be used both for individual numerical evaluations and for graphical visualization.

Boundary Value Problems

A boundary value problem specifies conditions at more than one value of the independent variable. For example, a second-order problem might impose

y(0)=a,y(1)=b.y(0)=a,\qquad y(1)=b.y(0)=a,y(1)=b.

The numerical solver determines a function satisfying both conditions over the interval. When a solution procedure is passed to a plotting routine, Maple can often infer the relevant interval from the boundary conditions.


Nonlinear ODEs and DAEs

A leading derivative is nonlinear when the highest derivative does not appear linearly. For example, if the equation contains a term such as

(y′(t))2,\left(y'(t)\right)^2,(y′(t))2,

then the equation is nonlinear in the highest derivative.

Such equations can often be treated numerically as differential-algebraic systems. An important issue is that solving for y′(t)y'(t)y′(t) from (y′(t))2\left(y'(t)\right)^2(y′(t))2 produces two possible signs:

y′(t)=±known quantity.y'(t)=\pm\sqrt{\text{known quantity}}.y′(t)=±known quantity​.

Consequently, an additional initial condition may be required to identify the intended branch. The value of y′(0)y'(0)y′(0) determines whether the positive or negative branch is selected.

Maple can also handle more complicated DAEs, including higher-index systems, using specialized numerical techniques.


Delay Differential Equations

A delay differential equation contains values of the solution at earlier times, such as

y′(t)=f(t,y(t),y(t−τ)),y'(t)=f\bigl(t,y(t),y(t-\tau)\bigr),y′(t)=f(t,y(t),y(t−τ)),

where τ\tauτ is a delay.

A simple example uses a delay of one time unit. The solution requires a history function for times before the starting time. If only a value such as y(0)=0y(0)=0y(0)=0 is specified, Maple commonly assumes that value for the prior interval as well.

This assumption can produce an initially unusual solution:

  • During the first delay interval, the solution reflects the assumed history.

  • After the delay interval has passed, the computed solution begins responding to its own evolving values.

  • The transition may appear smoother after the first delay period.

Nonconstant History Functions

A constant history is not always appropriate. A problem may instead specify

y(t)=ϕ(t),−τ≤t≤0,y(t)=\phi(t),\qquad -\tau\leq t\leq 0,y(t)=ϕ(t),−τ≤t≤0,

where ϕ(t)\phi(t)ϕ(t) is a nonconstant function.

Until a direct history-function specification is available for a particular formulation, the same effect can be represented using a piecewise expression. The piecewise definition uses the prescribed history before the initial time and the computed solution afterward.

The choice of history can substantially change the solution. A constant approximation may be qualitatively different from an exponential or other physically motivated history.


Partial Differential Equations

Maple has native numerical support primarily for one-space-variable, one-time-variable PDEs. These problems are solved using numerical PDE methods such as finite-difference schemes.

The PDE formulation includes:

  • The PDE itself.

  • Initial conditions.

  • Boundary conditions.

  • Numerical-method options when needed.

Instead of returning only a numerical procedure, the PDE solver returns a solution module. The module provides access to:

  • Numerical solution values.

  • One-dimensional solution procedures at selected times.

  • Two-dimensional or three-dimensional plots.

  • Animations over time.

For example, a solution module can provide a function u(x,t0)u(x,t_0)u(x,t0​) for a fixed time t0t_0t0​, or directly generate a surface representing u(x,t)u(x,t)u(x,t) over space and time.

Standard finite-difference methods include schemes such as:

  • Lax–Friedrichs.

  • Leapfrog.

  • DuFort–Frankel.

For many standard PDEs, Maple can select an appropriate method automatically.


Advanced Initial-Value Problem Features

High-Precision Numerical Solutions

Maple supports arbitrary numerical precision. The working precision is controlled by the number of requested digits.

For a high-accuracy computation, one can:

  • Set the working precision to a value such as 30 digits.

  • Specify absolute and relative error tolerances.

  • Select a high-order integration method.

  • Compare the numerical result with a known exact solution.

For example, a harmonic oscillator with an exact sinusoidal solution can be used to test the numerical accuracy.

High-order Runge–Kutta pairs can achieve high precision, but they may require many right-hand-side evaluations. In the example discussed, a seventh/eighth-order Runge–Kutta pair required approximately tens of thousands of function evaluations to integrate to t=10t=10t=10 with a tolerance near 10−2510^{-25}10−25.

Taylor-Series Methods

Taylor-series methods are often more efficient when very high accuracy is required. Instead of taking many small Runge–Kutta steps, the method uses high-order local expansions.

The key conclusion is:

Taylor-series integration is particularly useful when stringent accuracy requirements make conventional step methods expensive.

The Taylor result agreed closely with the known exact solution while requiring substantially less computation in the demonstrated example.


Stiff Differential Equations

A stiff problem contains widely separated time scales. Explicit methods may be forced to take extremely small steps even when the desired solution varies relatively slowly.

A standard nonstiff Runge–Kutta–Fehlberg method, such as RKF45, may require roughly tens of thousands of right-hand-side evaluations on a stiff problem.

A stiff solver, such as a Rosenbrock method, can be selected using the stiff option. The stiff method required only several hundred evaluations in the example, producing a major efficiency improvement.

Practical Principle

  • Nonstiff methods are usually effective for smoothly varying problems with comparable time scales.

  • Stiff methods are preferable when rapidly decaying modes or strong stability restrictions are present.

  • Applying a nonstiff method to a stiff problem can be unnecessarily expensive or may cause numerical failure.


Event Handling

Event Structure

An event has two fundamental components:

  1. A trigger, which determines when the event occurs.

  2. An action, which determines what Maple does when the trigger fires.

Events allow a simulation to respond to discrete conditions during continuous integration.

Event Triggers

Common trigger types include:

Zero Crossings

An event can be triggered when an expression passes through zero. For example, the event may occur when

y(t)−2=0.y(t)-2=0.y(t)−2=0.

This is useful for detecting crossings, threshold attainment, or sign changes.

Conditional Triggers

A zero crossing or other trigger can be combined with a condition. This allows an event to fire only when an additional logical requirement is satisfied.

Conditional triggers are useful when the same expression reaches a threshold multiple times but only one occurrence is relevant. For example, a trigger can be restricted to a particular phase, region, or state of the system.

Range Violations

An event can be triggered when a quantity leaves a specified interval:

a≤y(t)≤b.a\leq y(t)\leq b.a≤y(t)≤b.

This is useful for stopping or reassessing a simulation when a physical or numerical constraint is violated.

Time-Based Triggers

Events can occur at:

  • A specific time.

  • Repeated periodic times.

  • A starting time followed by a fixed period.

For example, an event can begin at t=2t=2t=2 and then occur every 0.50.50.5 time units.

Event Actions

Possible actions include:

  • Halting the integration.

  • Executing one statement.

  • Executing multiple statements.

  • Resetting or reinitializing variables.

  • Updating discrete variables.

  • Running a state-machine transition.

Halting at a Threshold

Suppose the model is

y′(t)=y(t),y'(t)=y(t),y′(t)=y(t),

and an event halts the simulation when y=2y=2y=2. If integration is requested beyond that point, Maple reports that the solution cannot be evaluated farther to the right because the event caused a halt. The returned value corresponds to the time at which yyy reached 2.

Reinitialization

Instead of stopping, an event can reset a variable. For example:

  • Integrate until y=2y=2y=2.

  • Reset yyy to 1.

  • Continue integrating.

  • Repeat the process whenever yyy reaches 2.

This produces repeated threshold-and-reset behavior.

Discrete Variables

A discrete variable changes only when an event action updates it. For example, a variable num_reset can count how many times a reset occurs:

  1. Reset yyy to 1.

  2. Increment the reset counter by 1.

Plotting the counter produces a staircase. Each jump corresponds to one event occurrence.

Discrete variables are also appropriate when a quantity changes during a simulation. If a parameter must change in response to an event, it is often better modeled as a discrete variable rather than as a fixed parameter.

State Machines

A state machine represents a collection of discrete equations or actions evaluated in a specified order.

The begin and end controls determine how execution moves through the discrete-equation list:

  • Begin: return to the start of the discrete-equation sequence.

  • End: jump to the end of the sequence.

State machines are useful for systems with modes, switching logic, resets, or conditional transitions.


Parameterized ODEs and Compilation

Parameterized Problems

An ODE can contain parameters whose values are supplied after the numerical solution procedure is created. For example, a harmonic oscillator may depend on:

  • A frequency parameter.

  • An initial-slope parameter.

  • Other physical coefficients.

If the parameters have not been assigned, Maple cannot evaluate the numerical solution because the right-hand side is not fully numeric.

A typical workflow is:

  1. Define the ODE with symbolic parameters.

  2. Request a numerical solution procedure.

  3. Query the parameters associated with the problem.

  4. Assign numerical values to them.

  5. Evaluate or plot the solution.

  6. Change the parameters and repeat.

Changing the parameter values modifies the solution procedure so that subsequent evaluations use the new values.

On-Request Computation

Parameterized IVP solutions are computed on request:

  • No complete solution is necessarily calculated immediately.

  • Numerical values are generated when requested.

  • Changing parameters causes later requests to use the new parameter values.

  • The computation engine can reuse information when appropriate.

This is especially useful when a single model must be evaluated repeatedly for many parameter choices.

Compiled Right-Hand Sides

The compile option compiles the model’s right-hand-side procedure. This can substantially reduce computation time when the solution is evaluated many times.

Compilation is especially valuable when:

  • The model is large.

  • Many parameter values must be tested.

  • The ODE is integrated repeatedly.

  • The right-hand-side evaluation is computationally significant.

  • Parameter searching or optimization is required.

Even when the integration engine is already compiled, compiling the user-defined right-hand side can help. In the demonstrated example, repeated parameter evaluations were significantly faster with compilation enabled.

Recent Maple versions include a compiler that works without requiring the user to separately configure an external compiler in many environments.


Interactive Control of Numerical Solutions

A numerical solution procedure can be queried and controlled after it has been created.

Information That Can Be Queried

Available information includes:

  • The numerical method being used.

  • The number of right-hand-side evaluations.

  • The number of events that have fired.

  • The time of the most recent event.

  • Current parameter values.

  • The problem’s parameter names.

  • Current initial values.

  • The last solution value computed.

  • Event status.

  • Array-output configuration.

For example, a problem may report that the Rosenbrock method is being used, that the initial value is y(0)=0y(0)=0y(0)=0, and that no last value exists because the procedure has not yet been evaluated.

Last Computed Value

After evaluating a solution at a requested point, the procedure can report the last value actually computed.

This is important when an event interrupts integration. If evaluation was requested at t=100t=100t=100 but an event halted the computation at t≈3.14t\approx3.14t≈3.14, the last-value query identifies the actual stopping point.

Clearing Events

A halted event can be cleared so that integration continues:

  1. Request a value beyond the event.

  2. The event halts the integration.

  3. Query the last computed value.

  4. Clear the event.

  5. Resume integration.

  6. Stop again at the next event, if applicable.

This permits controlled, interval-by-interval integration.

Disabling Events

Disabling an event turns it off entirely, making the integrator behave as though that event had not been specified.

Disabling differs from clearing:

  • Clearing removes the current halt or event state and allows continuation.

  • Disabling deactivates the event mechanism itself.

When an event is disabled after a computation has already occurred, Maple may reintegrate from the beginning without that event.

Array Output

Newer Maple versions can return numerical results as an array or table-like data structure. The output may include columns such as:

  • ttt.

  • y(t)y(t)y(t).

  • y′(t)y'(t)y′(t).

  • Parameter values such as aaa and bbb.

An array request can specify:

  • The final integration time.

  • The number of equally spaced output points.

For example, integrating to t=10t=10t=10 with 101 points provides data suitable for:

  • Matrix construction.

  • Standard plotting.

  • Exporting or saving.

  • Input to other numerical routines.

Array output is convenient when a procedural solution is no longer needed and a complete sampled data set is desired.


Parameter Optimization

General Optimization Workflow

A parameterized numerical solution can be embedded inside an objective function. The objective function:

  1. Accepts a parameter value.

  2. Assigns that value to the numerical ODE procedure.

  3. Integrates the system.

  4. Extracts a desired solution value.

  5. Returns that value to an optimization or root-finding command.

Example: Matching a Target Value

Suppose the goal is to find a parameter aaa such that

y(1;a)=2.y(1;a)=2.y(1;a)=2.

An objective function can return y(1;a)y(1;a)y(1;a). The desired parameter satisfies

F(a)=2,F(a)=2,F(a)=2,

where

F(a)=y(1;a).F(a)=y(1;a).F(a)=y(1;a).

A root-finding command such as fsolve can then determine aaa.

The numerical solver may be compiled to make repeated objective evaluations faster.

Delayed Evaluation

When an objective function is passed to a solver, its argument must not be evaluated before the solver supplies a numerical value.

If Maple tries to evaluate the objective with an unassigned symbolic variable xxx, the numerical ODE solver reports that it requires a numeric parameter. Delayed evaluation prevents this premature computation.

The evaluation process is therefore:

  1. Define the objective without immediately evaluating it at symbolic xxx.

  2. Pass the delayed objective to the root finder.

  3. Let the root finder supply numerical trial values.

  4. Integrate the ODE for each trial value.

Damped Harmonic Oscillator Optimization

A damped oscillator can be written conceptually as

My′′(t)+Cy′(t)+Ky(t)=0,M y''(t)+C y'(t)+K y(t)=0,My′′(t)+Cy′(t)+Ky(t)=0,

where:

  • MMM is the mass.

  • CCC is the damping coefficient.

  • KKK is the spring constant.

The objective is to choose CCC so that the energy falls below a measurement threshold as quickly as possible.

The mechanical energy is the sum of kinetic and potential energy:

E(t)=12M(y′(t))2+12K(y(t))2.E(t)=\frac{1}{2}M\left(y'(t)\right)^2+\frac{1}{2}K\left(y(t)\right)^2.E(t)=21​M(y′(t))2+21​K(y(t))2.

An event halts the integration when

E(t)=10−6.E(t)=10^{-6}.E(t)=10−6.

The objective function returns the event time. Minimizing this function determines the damping coefficient that produces the fastest measurable decay.

Local Versus Global Behavior

Root-finding and minimization procedures generally locate local solutions. The objective function may have:

  • A shallow local minimum.

  • A global minimum at another parameter value.

  • Different behavior on different intervals.

Therefore, it is important to plot or inspect the objective function before optimization. Restricting the search interval can prevent the algorithm from converging to an undesired local minimum.

In the damped oscillator example, the mathematically familiar critical-damping value is not necessarily the optimum under a finite measurement threshold. Critical damping minimizes the time to reach zero in an idealized sense, but the practical objective stops at a small nonzero energy, changing the optimal value.


Boundary Value Problems

Basic BVPs and Boundary Layers

A boundary value problem imposes conditions at both ends of an interval. A problem with a large coefficient can produce boundary layers, where the solution changes rapidly near one or both boundaries.

As the coefficient increases, the boundary layers become narrower and more difficult to resolve numerically. The solver may need:

  • A finer adaptive mesh.

  • Tighter or relaxed error tolerances.

  • An appropriate numerical method.

Singular Coefficients

Some BVPs contain coefficients that become singular at an endpoint. Such problems often arise after transforming equations into spherical or polar coordinates, where radial terms may contain denominators involving the radius rrr.

Direct numerical evaluation at the singular endpoint can fail. Maple provides midpoint methods designed to handle such singular-coefficient problems.

The midpoint method avoids evaluating the singular expression exactly at the problematic endpoint while still approximating the solution accurately.

When an exact solution is available, it can be used to verify the numerical result. Tightening the absolute error tolerance generally produces a more accurate solution.

For BVPs, the solver primarily uses absolute error, rather than the separate relative-error control commonly used for IVPs.


Difficult Nonlinear BVPs

A challenging BVP may combine:

  • A very small coefficient multiplying the leading derivative.

  • Strong nonlinearity.

  • A narrow interior boundary layer.

Direct Newton iteration can fail to converge for the desired problem. A useful diagnostic approach is to introduce a parameter into the difficult coefficient and solve a sequence of easier problems first.

For example, replace a small coefficient ε\varepsilonε with a larger value:

ε=1,110,180,…\varepsilon=1,\quad \frac{1}{10},\quad \frac{1}{80},\quad \ldotsε=1,101​,801​,…

The larger-coefficient problems may be easy to solve, while the smaller-coefficient problems gradually develop a sharp interior layer.

Mesh Refinement

When the layer becomes too narrow, Maple may report that the requested accuracy cannot be achieved with the current maximum mesh size.

Increasing the maximum number of mesh points can help:

  • A moderate increase may resolve the layer.

  • A much smaller coefficient may require hundreds of mesh points.

  • Eventually, simply increasing the mesh may no longer be sufficient.


Continuation

Continuation solves a difficult problem by gradually transforming a known easy problem into the desired problem.

Introduce a continuation parameter ppp with

0≤p≤1.0\leq p\leq1.0≤p≤1.

Construct the model so that:

  • At p=0p=0p=0, the equation is easy to solve.

  • At p=1p=1p=1, the equation is the target problem.

The numerical solver uses the solution at one continuation stage as an initial approximation for the next stage.

Continuation is effective for:

  • Small leading coefficients.

  • Strongly nonlinear equations.

  • Boundary layers.

  • Problems with poor initial guesses.

  • Systems that can be gradually changed from linear to nonlinear.

It requires some experimentation because the continuation path must be chosen carefully. Nevertheless, it can resolve very sharp interior layers that direct solution methods cannot handle.


Eigenvalue and Eigenfunction Problems

The Basic Eigenvalue Problem

A typical eigenvalue problem has the form

y′′(x)+c2y(x)=0,y''(x)+c^2y(x)=0,y′′(x)+c2y(x)=0,

with boundary conditions such as

y(0)=0,y(1)=0.y(0)=0,\qquad y(1)=0.y(0)=0,y(1)=0.

The zero function satisfies these conditions for every ccc, so a normalization condition is needed to exclude the trivial solution. A common choice is

y′(0)=1.y'(0)=1.y′(0)=1.

Only certain discrete values of ccc allow the solution to satisfy the second boundary condition. These are the eigenvalues, and the corresponding nonzero solutions are eigenfunctions.


Shooting Method

The shooting method converts the BVP into an IVP:

  1. Treat ccc as an unknown parameter.

  2. Choose a normalization such as y′(0)=1y'(0)=1y′(0)=1.

  3. Integrate from x=0x=0x=0 to x=1x=1x=1.

  4. Define the objective function $$ F(c)=y(1;c). $$

  5. Find values of ccc satisfying $$ F(c)=0. $$

Plotting F(c)F(c)F(c) reveals approximate zero crossings. Root-finding can then refine the eigenvalues.

For the simple wave-equation example, the first several crossings occur near successive multiples of π\piπ. Once an eigenvalue is found, it can be substituted into the numerical solver to obtain and plot the corresponding eigenfunction.

The shooting method is systematic because the objective function reveals the locations of the eigenvalues.


Piecewise-Polynomial Output

A numerical solution does not have to remain an opaque procedure. Maple can return an approximation as a piecewise polynomial over the requested interval.

Each polynomial is valid on a subinterval and is typically represented in Horner form. Horner form reduces roundoff error and makes polynomial evaluation efficient.

A piecewise-polynomial solution can be differentiated, allowing direct access to:

  • The function.

  • Its first derivative.

  • Its second derivative.

For the eigenvalue problem, the second derivative should satisfy the original differential equation. For example, from

y′′(x)+c2y(x)=0,y''(x)+c^2y(x)=0,y′′(x)+c2y(x)=0,

one expects

y′′(x)=−c2y(x).y''(x)=-c^2y(x).y′′(x)=−c2y(x).

Plotting the function and its derivatives provides a useful consistency check.

Binary Piecewise Representation

A standard piecewise function tests its conditions sequentially. If it contains NNN branches, evaluating a point near the end may require up to NNN comparisons.

This can cause:

  • Linear-time evaluation for one point.

  • Slower plotting as the number of branches increases.

  • Inefficiency when the piecewise representation has hundreds of intervals.

A binary piecewise representation organizes the branches as a binary decision tree. Its evaluation depth is approximately

log⁡2(N),\log_2(N),log2​(N),

rather than NNN.

The binary form is usually much larger and less readable when displayed, but it provides more uniform evaluation performance. The speed advantage becomes more significant as the number of polynomial branches grows.


BVP Approach to Eigenvalue Problems

Eigenvalue problems can also be solved directly with the BVP solver.

The BVP solver treats an unknown parameter as an additional degree of freedom. A second-order two-point BVP with one free parameter can be supplied with three conditions:

  • Two boundary conditions.

  • One normalization condition.

The normalization remains essential because the zero solution otherwise satisfies the homogeneous problem.

Initial Approximation

The BVP solver requires an approximate solution for both:

  • The eigenvalue.

  • The eigenfunction.

For the first eigenfunction, a simple trial function such as

ytrial(x)=x(1−x)y_{\text{trial}}(x)=x(1-x)ytrial​(x)=x(1−x)

has the correct zero values at the endpoints and provides a nontrivial starting shape.

To locate higher eigenfunctions, the trial function must include the approximate number and placement of oscillations. For example:

  • A trial function with one interior zero can guide the solver toward the second eigenfunction.

  • A trial function with two interior zeros can guide it toward the third eigenfunction.

If the initial guess is too similar to a previous eigenfunction, the solver may return the same eigenvalue again.

Comparison of Methods

Shooting

  • More systematic.

  • Makes eigenvalue crossings visible.

  • Works well when the IVP is stable and easy to integrate.

  • Naturally reveals successive eigenvalues.

BVP Solver

  • Can solve directly for the eigenvalue and eigenfunction.

  • Does not necessarily require knowing all preceding eigenvalues.

  • Can refine an approximate eigenfunction.

  • Requires carefully chosen initial guesses.

  • May involve more trial and error.


Singular Eigenvalue Problems

Eigenvalue problems arising in polar or spherical coordinates may contain singular coefficients. The symbolic analysis needed to determine appropriate endpoint behavior may require the eigenvalue parameter to be known numerically in advance.

A practical workaround is to define a shooting routine that:

  1. Accepts a trial eigenvalue.

  2. Substitutes that value into the differential equation.

  3. Constructs the numerical IVP.

  4. Integrates to the opposite boundary.

  5. Returns the boundary residual.

The resulting residual function can then be plotted and searched for zeros. This approach is more computationally expensive than reusing one parameterized solution procedure, but it accommodates the symbolic endpoint analysis required by the singular problem.


Differential-Algebraic Equations

DAE Solver Methods

Maple’s primary DAE solvers use prolongation and projection extensions of Runge–Kutta-type methods.

Prolongation

Prolongation means differentiating algebraic constraints until the system reaches a form that can be integrated numerically.

  • An index-one DAE can generally be handled directly.

  • A higher-index DAE is differentiated until the necessary differential structure is exposed.

  • Further differentiation may reduce the system to index zero.

Projection

After each integration step, the numerical solution may drift away from the algebraic constraints. Projection corrects the solution so that the constraints remain satisfied.

The solver controls:

  • Error in the differential variables.

  • Error in the algebraic constraints.

The constraint error is incorporated into the overall error-control process.

Alternative Direct Method

MEBDFI is a direct DAE method that works with the original system without the same prolongation-and-projection process. In the examples discussed, prolongation–projection methods generally performed better.

These methods are also used in larger modeling environments and can handle systems involving thousands of equations.


Pendulum Example

A planar pendulum can be represented using Cartesian coordinates x(t)x(t)x(t) and y(t)y(t)y(t) subject to the constraint

x(t)2+y(t)2=1.x(t)^2+y(t)^2=1.x(t)2+y(t)2=1.

The differential equations describe the accelerations, while the algebraic equation forces the bob to remain on the unit circle.

The system is an index-three DAE. Maple can:

  • Perform the required symbolic manipulation.

  • Differentiate the constraint.

  • Determine hidden relationships.

  • Integrate the resulting system.

  • Project the numerical solution back onto the constraint manifold.

The resulting motion oscillates near the bottom of the circle. Plotting x(t)x(t)x(t) and y(t)y(t)y(t) shows the time evolution, while plotting (x(t),y(t))(x(t),y(t))(x(t),y(t)) displays the pendulum trajectory.


Index Reduction

Starting with

x(t)2+y(t)2=1,x(t)^2+y(t)^2=1,x(t)2+y(t)2=1,

differentiate once:

2x(t)x′(t)+2y(t)y′(t)=0.2x(t)x'(t)+2y(t)y'(t)=0.2x(t)x′(t)+2y(t)y′(t)=0.

Differentiate again:

2(x′(t))2+2x(t)x′′(t)+2(y′(t))2+2y(t)y′′(t)=0.2\left(x'(t)\right)^2+2x(t)x''(t) +2\left(y'(t)\right)^2+2y(t)y''(t)=0.2(x′(t))2+2x(t)x′′(t)+2(y′(t))2+2y(t)y′′(t)=0.

The second derivatives can be replaced using the original differential equations. This exposes an algebraic equation involving the previously unknown multiplier, often denoted by λ(t)\lambda(t)λ(t).

Two differentiations and an elimination are needed to determine λ(t)\lambda(t)λ(t) algebraically. A third differentiation would be needed to obtain a differential equation for λ(t)\lambda(t)λ(t), which is why the original system has index three.

The same reduction can be performed manually by:

  • Replacing the original constraint with the differentiated acceleration-level equation.

  • Supplying the constraint explicitly.

  • Solving the resulting system numerically.

This can produce the same solution as automatic index reduction.

For complicated multibody systems, alternative combinations of constraints may provide better numerical conditioning than simply differentiating each original constraint.


Delay in DAE Systems

Delay can be incorporated into DAE systems. For example, a pendulum model can use delayed values in force terms:

x(t−τ),y(t−τ).x(t-\tau),\qquad y(t-\tau).x(t−τ),y(t−τ).

The geometric constraint can still be maintained:

x(t)2+y(t)2=1.x(t)^2+y(t)^2=1.x(t)2+y(t)2=1.

However, the delay changes the dynamics:

  • The motion may no longer be truly periodic.

  • The swinging can become asymmetric.

  • The system can evolve differently from the nondelayed pendulum.

  • The trajectory can remain on the constraint circle while its timing and direction change.

Numerical Handling of Delays

The delay implementation relies on interpolants generated by the numerical integration method. These interpolants are accurate to approximately the same tolerance as the numerical solution.

To evaluate a delayed term, Maple stores enough information about prior solution values. The stored history must extend only as far back as the maximum required delay to limit memory use.

This is why delay handling requires:

  • An accurate interpolant.

  • Storage of prior solution information.

  • Retrieval of historical values during later evaluations.

The internal implementation is not generally exposed as research source code, but delay problems can be compiled when the model supports compilation.


Partial Differential Equations in One Dimension

Reaction–Diffusion System

A one-dimensional reaction–diffusion model can describe concentrations such as U(x,t)U(x,t)U(x,t) and V(x,t)V(x,t)V(x,t) for two reacting species.

The model includes:

  • Two dependent concentrations.

  • Constant input concentrations.

  • Two diffusion coefficients.

  • Reaction terms.

  • Initial and boundary conditions.

The numerical PDE solver can produce:

  • U(x,t0)U(x,t_0)U(x,t0​) and V(x,t0)V(x,t_0)V(x,t0​) at a selected time.

  • Three-dimensional surfaces over space and time.

  • Time histories at a fixed spatial location.

  • Animations of evolving concentration profiles.

Interpreting the Solution

At a fixed spatial point, the concentration may approach its equilibrium value. However, the approach need not be monotonic.

For example, a concentration expected to approach approximately 6 may:

  1. Begin above 6.

  2. Fall below 6.

  3. Rise again toward 6.

This overshoot may be mathematically valid but could suggest that the model’s assumptions need examination. In applications, nonmonotonic behavior can indicate missing reaction terms, omitted physical effects, or an oversimplified model.

The one-dimensional PDE solver uses a spatial discretization based on finite differences rather than automatically applying the method of lines with dsolve.


Higher-Dimensional PDEs Through the Method of Lines

Two-Dimensional Heat Equation

For a two-dimensional spatial domain, consider the heat equation

∂u∂t=D(∂2u∂x2+∂2u∂y2),\frac{\partial u}{\partial t} = D\left( \frac{\partial^2u}{\partial x^2} + \frac{\partial^2u}{\partial y^2} \right),∂t∂u​=D(∂x2∂2u​+∂y2∂2u​),

on a rectangular domain with zero boundary values:

u=0on the boundary.u=0 \quad\text{on the boundary}.u=0on the boundary.

Maple does not provide the same native general-purpose support for arbitrary two-dimensional spatial PDE domains. Rectangular domains are more manageable, while complicated geometries require additional work.

The method of lines handles the problem by:

  1. Discretizing the spatial coordinates.

  2. Replacing spatial derivatives with finite-difference formulas.

  3. Obtaining a large system of ODEs in time.

  4. Solving that ODE system numerically.

Spatial Grid

Divide each spatial interval into nnn subintervals. This creates an (n+1)×(n+1)(n+1)\times(n+1)(n+1)×(n+1) grid.

For a uniform grid spacing hhh, the second derivative can be approximated by

∂2u∂x2≈ui+1,j−2ui,j+ui−1,jh2,\frac{\partial^2u}{\partial x^2} \approx \frac{u_{i+1,j}-2u_{i,j}+u_{i-1,j}}{h^2},∂x2∂2u​≈h2ui+1,j​−2ui,j​+ui−1,j​​,

and similarly in the yyy direction:

∂2u∂y2≈ui,j+1−2ui,j+ui,j−1h2.\frac{\partial^2u}{\partial y^2} \approx \frac{u_{i,j+1}-2u_{i,j}+u_{i,j-1}}{h^2}.∂y2∂2u​≈h2ui,j+1​−2ui,j​+ui,j−1​​.

The semidiscrete equation becomes

dui,jdt=D[ui+1,j−2ui,j+ui−1,jh2+ui,j+1−2ui,j+ui,j−1h2].\frac{d u_{i,j}}{dt} = D\left[ \frac{u_{i+1,j}-2u_{i,j}+u_{i-1,j}}{h^2} + \frac{u_{i,j+1}-2u_{i,j}+u_{i,j-1}}{h^2} \right].dtdui,j​​=D[h2ui+1,j​−2ui,j​+ui−1,j​​+h2ui,j+1​−2ui,j​+ui,j−1​​].

Each interior node depends on:

  • Its own value.

  • Its neighboring node in the positive xxx direction.

  • Its neighboring node in the negative xxx direction.

  • Its neighboring node in the positive yyy direction.

  • Its neighboring node in the negative yyy direction.

Boundary and Initial Conditions

Boundary values are fixed directly. For zero boundary conditions:

u0,j=0,un,j=0,u_{0,j}=0,\qquad u_{n,j}=0,u0,j​=0,un,j​=0,

and

ui,0=0,ui,n=0.u_{i,0}=0,\qquad u_{i,n}=0.ui,0​=0,ui,n​=0.

Only interior nodes are treated as unknown time-dependent variables. With a 21×2121\times2121×21 grid, there are initially more than 400 grid points, but the fixed boundary values reduce the number of actual unknowns.

An initial profile can be assigned to the interior nodes. A suitable profile should:

  • Satisfy the boundary conditions.

  • Be nontrivial.

  • Represent the physical initial temperature or concentration distribution.

The resulting equations and initial conditions are passed to the ODE numerical solver.

Reconstructing and Plotting the Solution

The numerical solution consists of values at discrete grid points. To visualize it:

  1. Create a matrix containing the grid values.

  2. Insert the fixed boundary values.

  3. Arrange the values according to their spatial indices.

  4. Use a three-dimensional plotting structure to display the surface.

This procedure can generate:

  • A surface at the initial time.

  • A surface at later times.

  • An animation showing diffusion.

  • Direct comparisons between initial and evolved profiles.

As expected for the heat equation, the peak of the initial profile decreases over time as heat diffuses toward the boundaries.

Extension to Three Spatial Dimensions

The same method can be extended to a PDE involving xxx, yyy, zzz, and ttt. However, the number of unknowns grows rapidly.

A grid with approximately 20 points in each spatial direction contains on the order of

203=800020^3=8000203=8000

spatial locations before accounting for boundary constraints. This rapidly increases memory and computation requirements.

For higher-dimensional problems, sparse data structures, efficient discretization, and compiled computations become increasingly important.


Efficient Construction of Large Maple Data Structures

When constructing large sets of equations or boundary conditions, Maple’s seq mechanism is generally more efficient than repeatedly appending items in a for loop.

A repeated append operation may create many intermediate data structures:

  • A structure of length 1.

  • Then length 2.

  • Then length 3.

  • Continuing until the final size is reached.

This can require unnecessary memory and lead to approximately quadratic construction cost.

A sequence-generation approach constructs the final collection without repeatedly rebuilding all intermediate versions. For large systems, this can substantially improve setup time and memory use.


Programmer Interface for Numerical ODEs

When the Standard Equation Form Is Insufficient

Some models cannot be passed directly to the ordinary equation interface. For example, an equation may contain an integral operator such as

∫0tg(s,y(s)) ds.\int_0^t g(s,y(s))\,ds.∫0t​g(s,y(s))ds.

In such cases, Maple’s programmer interface can define the system as a vector of first-order differential equations and provide a procedure for evaluating the right-hand side.

The standard process is:

  1. Rewrite the system as first-order equations.

  2. Define a procedure that evaluates the right-hand side.

  3. Allow the procedure to call arbitrary Maple functionality.

  4. Pass the procedure to the numerical solver.

The procedure can call operations such as numerical or symbolic integration. During integration, Maple may repeatedly evaluate the integral for different values of ttt.

Limitations of Compilation

The procedure interface can call complicated Maple code, but compilation may not be possible when the procedure contains unsupported or highly dynamic operations.

Therefore:

  • The programmer interface provides flexibility.

  • Compilation provides speed when supported.

  • A complicated procedure may need to run in interpreted Maple code.

Use with Method-of-Lines Models

The programmer interface is especially useful for large discretized PDE systems. Instead of explicitly writing hundreds or thousands of individual equations, a compact procedure can loop over the spatial grid and compute the right-hand side values.

This approach can make it easier to:

  • Build large systems.

  • Specify initial conditions.

  • Modify the discretization.

  • Experiment with different PDEs.

  • Avoid unwieldy symbolic equation lists.

The programmer interface is therefore both a practical computational tool and a useful way to implement method-of-lines discretizations.


Key Principles

Use dsolve(..., numeric) for numerical ODE, DAE, and delay problems; use the numerical PDE solver for supported one-dimensional PDEs.

Use high-order Taylor methods for very high accuracy and stiff methods for stiff systems.

Use events to detect thresholds, halt integration, reset variables, update discrete states, or implement state machines.

Parameterization combined with compilation is highly effective for repeated simulation, parameter searches, and optimization.

Continuation can transform a difficult BVP into a sequence of easier problems and is especially useful for sharp boundary layers.

Eigenvalue problems require normalization to exclude the trivial solution, and shooting provides a systematic way to locate eigenvalues.

DAE solvers use index reduction, constraint monitoring, and projection to preserve algebraic relationships such as pendulum constraints.

Higher-dimensional PDEs can be solved through spatial finite differences and the method of lines, but computational cost grows rapidly with dimension.

Efficient construction of large Maple data structures is important; generating sequences directly avoids the repeated copying associated with incremental appending.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent