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

Speaker 1Speaker 2

Numerical Methods in Maple

21:39
0:00-21:39
  1. Corey

    Welcome back. Today we're working through numerical differential equations in Maple, with a focus on what Maple can solve and how to control the numerical process. The main tool for univariate ordinary differential equations is dsolve with the numeric option, which returns a numerical solution procedure rather than attempting an exact symbolic solution.

  2. Maria

    And that covers several important problem types: initial value problems, boundary value problems, delay differential equations, differential-algebraic equations, and partial differential equations. For an initial value problem, you provide conditions at one independent-variable point. For example, a harmonic oscillator with y at zero equal to one and y prime at zero equal to zero can be passed directly to dsolve with numeric, and then the returned procedure can be evaluated at any requested point.

  3. Corey

    Boundary value problems are similar, except the conditions can be specified at more than one point. If a differential equation has one condition at zero and another at one, dsolve with numeric can still produce the solution procedure. Maple's odeplot command can then plot that solution, and for a boundary value problem it can detect the interval from the problem and choose the appropriate plotting range.

  4. Maria

    Maple can also handle nonlinear ordinary differential equations and more complicated DAEs. In one example, the highest derivative appears quadratically, through a squared first derivative, so the problem can be treated as a differential-algebraic equation. An additional initial condition is needed because squaring loses the sign: positive and negative values of the derivative can produce the same squared value.

  5. Corey

    Delay equations are supported too. Consider a simple equation with a delay of one time unit. If the history before time zero is assumed to be constant, the solution can initially show a simple, nearly constant behavior, because the delayed values are still coming from that prescribed history. Once the integration moves beyond the delay interval, the solution begins changing more smoothly in response to its own earlier values.

  6. Maria

    Partial differential equations have more limited native support. Maple directly handles one-space, one-time PDEs using numerical PDE methods such as Lax-Friedrichs, leapfrog, and DuFort-Frankel. You provide the PDE together with the initial and boundary conditions, and instead of receiving a procedure directly, you receive a solution module.

  7. Corey

    That module is useful because it gives direct access to visualization. You can request the solution at a particular time, obtain a procedure for evaluating it over space, or ask the module for a plot. It can also produce an animation over a time interval and a three-dimensional plot showing the solution as a function of both time and space.

  8. Maria

    Let's look more closely at initial value problems. Maple offers high-accuracy techniques such as Taylor series, standard step solvers such as Rosenbrock and LSOD, event handling, reinitialization, state machines, parameterized problems, compilation, and interactive controls. The help links associated with these features describe the available options in detail.

  9. Corey

    Arbitrary precision is another important capability. You can set the number of digits, for example to thirty, and request absolute and relative errors no larger than ten to the minus twenty-five. A high-order Runge-Kutta pair such as a 7-8 method can achieve that accuracy, but it may require many function evaluations.

  10. Maria

    For high-accuracy requirements, Taylor series can be substantially faster. In the harmonic oscillator example, the high-order Runge-Kutta calculation required roughly forty-two thousand function evaluations, while the Taylor-series approach was much quicker and produced comparable, even slightly better, precision under the stated tolerance. So Taylor series is a particularly useful choice when very high accuracy is the priority.

  11. Corey

    Stiff problems require a different strategy. A standard RKF45 method applied to a standard stiff problem needed roughly twenty thousand right-hand-side evaluations to reach time ten. With stiff set to true, Maple used a stiff method and needed only about five hundred eighty-eight evaluations. The lesson is practical: identifying stiffness and selecting a stiff method can make the computation dramatically more efficient.

  12. Maria

    Events let you interrupt or modify an integration when something important happens. Every event has two parts: a trigger, which says when the event occurs, and an action, which says what Maple should do. Triggers can include an expression passing through zero, a condition becoming true, a value leaving a specified range, a particular time, or a periodic schedule such as beginning at time two and repeating every half second.

  13. Corey

    The action might be halt, one or more Maple statements, or a state machine. For example, take y prime equal to y and stop when y reaches two. If you integrate toward time ten, Maple halts at the event and reports that it cannot continue to the right because the halt trigger fired. The returned value is the solution at the exact event time.

  14. Maria

    Instead of halting, the event can reinitialize the problem. In that same example, reset y to one every time it reaches two, and the solution repeatedly rises to two and jumps back to one. You can also declare a discrete variable, such as num reset, and increment it whenever the reset occurs. Plotting that variable gives a staircase showing how many resets have happened.

  15. Corey

    State machines extend this idea by combining events with discrete variables and ordered discrete equations. The equations run in the order specified. An action labeled to begin returns to the beginning of that set of discrete equations, while to end jumps to the end. Conditional triggers combine a trigger with an additional condition, so an event fires only when the relevant situation is the one being encountered.

  16. Maria

    Numerical initial value solutions are computed on request. The object returned by dsolve does not necessarily calculate the entire solution immediately; values are computed when you ask for them, unless the requested value is already known or is the immediately preceding value. This makes it convenient to create a solution engine and then query only the points you actually need.

  17. Corey

    Parameters fit naturally into this on-request model. Suppose the harmonic oscillator includes a frequency and an initial slope, represented by parameters A and B. You declare those parameters, obtain the solution object, and then ask Maple which parameters the problem contains. Before assigning numerical values, requesting a solution produces an error because Maple does not yet know what A and B are.

  18. Maria

    Once you set the parameter values, the same solution procedure can be evaluated or plotted. If you change the parameter values later, the procedure is updated, and subsequent computations use the new values. This is especially useful for repeatedly exploring how a solution changes as parameters vary.

  19. Corey

    Compilation makes repeated parameter studies much faster. In one test, roughly one hundred integrations with different parameter values were performed without compilation and then repeated with compile set to true. The compiled version was significantly faster because the right-hand-side function was compiled as well as the already compiled integration engine.

  20. Maria

    That combination is valuable for parameter searches, optimization, and other situations requiring many solves. In recent Maple versions, compilation works out of the box because a version of GCC ships with Maple. Earlier Windows versions required setting up Microsoft Visual C++.

  21. Corey

    The numerical solution procedure is also interactive. You can query the method used, the current initial conditions, the last value computed, the current parameter values, the number of function evaluations, and how many times events have fired. You can also inspect when the last event occurred.

  22. Maria

    For example, if an event halts a calculation at time about 3.14 even though you requested a value at time one hundred, the last-value query tells you where the integration actually stopped. You can clear the event and continue, then clear it again at the next occurrence. Alternatively, you can disable the event entirely, in which case Maple resumes as though that event had never been specified, reintegrating from the beginning.

  23. Corey

    Maple 2025 also adds array output. Asking for array information tells you which columns will be returned, such as t, y of t, y prime, and the parameter values A and B. You can then request a fixed number of output points, save the resulting data, pass it to other tools, or convert selected columns into a matrix for direct plotting.

  24. Maria

    If a quantity changes during the simulation, it is usually better represented as a discrete variable rather than a parameter. A parameter describes a value selected for a computation, while a discrete variable can be assigned a new value by an event during that computation. That distinction is important when modeling changes triggered by the evolving solution.

  25. Corey

    The same parameterized solution procedures can be used for optimization. Suppose we want to find A so that the solution satisfies y at one equal to two. We define an objective function that accepts a numerical parameter, assigns it to the solution, integrates to one, and returns y at one. Once that function has one input and one output, fsolve can find the parameter value that makes the returned result equal to two.

  26. Maria

    A more interesting example uses a damped harmonic oscillator. With mass and spring constant fixed at one, the damping constant becomes the parameter to optimize. The objective is the time required for the total kinetic plus potential energy to fall to one millionth, detected using an event that halts the integration at that energy level.

  27. Corey

    The objective function then accepts a damping value, runs the compiled numerical solve, and returns the time at which the energy event occurred. Plotting that function before optimizing is important because minimize and fsolve find local solutions. In the example, restricting the search range avoids a local minimum and gives an optimum damping value of about 1.81, with a minimum time of about 6.88.

  28. Maria

    That result is not exactly the usual critical-damping value of two because the objective does not ask for the solution to reach exactly zero. It asks when the measurable energy reaches a threshold of one millionth. The optimum therefore reflects the sensor resolution or stopping criterion, not the idealized requirement of complete decay.

  29. Corey

    When defining an objective for fsolve, unevaluation quotes can be necessary. Without them, Maple may try to evaluate the objective while its input is still the symbolic variable x, even though the numerical solver expects a number. Unevaluation quotes delay the calculation until fsolve supplies a numerical value for x.

  30. Maria

    For boundary value problems, Maple can handle boundary layers and even singular coefficients at an endpoint. Singular problems often arise after converting equations in spherical or polar coordinates, where a radius appears in a denominator. In such cases, the ordinary numerical approach may complain and require a midpoint method, such as the available midpoint variants, to handle the singular endpoint.

  31. Corey

    Tolerances matter here too. Boundary value problems use absolute error, rather than separate absolute and relative errors as in initial value integration. Tightening the absolute tolerance produces a more accurate solution. For a difficult nonlinear problem with a very small leading-derivative coefficient, however, simply tightening settings may not be enough.

  32. Maria

    A small coefficient can create a very sharp interior boundary layer. An easier version of the problem may solve readily when the coefficient is one, one tenth, or one eightieth, but fail as the coefficient becomes smaller. Increasing the maximum mesh from 128 to 512 points can help resolve a boundary layer, but eventually even a large mesh may not succeed.

  33. Corey

    That is where continuation becomes useful. You introduce a continuation parameter p and construct the coefficient so that p equal to zero gives an easy problem and p equal to one gives the difficult target problem. Maple solves the easier problem first and gradually moves toward the target, using the preceding solution to guide the next step. Continuation is powerful, but choosing a good path often requires trial and error and some understanding of the model.

  34. Maria

    Eigenvalue problems provide another important application. For the wave equation with zero boundary values at both ends, the zero function is always a solution, but it is uninteresting. Nonzero solutions exist only for discrete values of the parameter C. The shooting method treats C as unknown, chooses a nonzero initial slope for normalization, solves the resulting initial value problem, and searches for C values that make y at one equal to zero.

  35. Corey

    The shooting objective function is simply the value of y at the right endpoint as a function of C. Its zeros identify eigenvalues. Plotting it reveals several crossings, and solving near those crossings produces the corresponding eigenvalues and eigenfunctions. A solution procedure can then be used to plot a selected eigenfunction and verify that it satisfies the endpoint condition.

  36. Maria

    The same eigenvalue problem can be approached with Maple's boundary value solver. You still need a normalization condition to avoid the zero solution, and the solver can treat a free parameter as an additional degree of freedom. You provide approximate values for the parameter and the function, and the solver refines them. This method is less systematic because the quality of the result depends on the initial guesses, but it does not require knowing how many earlier eigenvalues have already been found.

  37. Corey

    For example, an approximate arc such as x times one minus x can lead to one eigenfunction. To find a later one, you can use an initial approximation with more bumps and a different parameter guess. If Maple returns a duplicate eigenvalue, it has essentially found the same function again, so the initial guess needs to be changed. The shooting method is generally better for systematic searches, while the boundary value approach can directly refine a particular mode.

  38. Maria

    Solutions can be returned in a more tangible form than an opaque procedure. With an appropriate output option, Maple can produce a piecewise polynomial approximation over a specified interval. The ordinary piecewise form checks its branches sequentially, so evaluation becomes slower as the number of branches grows. A piecewise-binary form uses nested binary decisions, reducing the number of comparisons from linear in the number of branches to logarithmic, which can help for larger solutions.

  39. Corey

    Now let's turn to differential-algebraic equations. Maple's main DAE methods are prolongation-projection extensions of Runge-Kutta methods. Prolongation means differentiating the constraints until the system reaches an index-one form, while projection enforces the constraints after each numerical step. Maple controls both the differential error and the constraint error.

  40. Maria

    The RKF45, CK45, and Rosenbrock approaches handle index-one problems directly. Higher-index systems require prolongation, after which constraint errors are monitored and corrected by projection. Maple also has the direct MEBDFI method, but the prolongation-projection approaches generally perform better in the examples described. These methods are also used by MapleSim for systems involving thousands of equations.

  41. Corey

    A simple index-three example is a two-dimensional pendulum. The differential equations describe the Cartesian coordinates x and y, while an algebraic constraint keeps the bob on a circle of radius one. Maple can solve this system numerically, plot x and y over time, and plot the trajectory in Cartesian coordinates.

  42. Maria

    To see the index reduction, differentiate the circular constraint once to obtain a relation involving the velocities. Differentiate again to obtain a relation involving second derivatives, substitute the known differential equations, and eliminate those second derivatives. This produces an algebraic equation that determines the previously unknown multiplier. A third differentiation would be needed to obtain a differential equation for that multiplier, which is why the original system has index three.

  43. Corey

    You can also perform that reduction manually by replacing the original constraint equation with the derived equation for the multiplier and specifying the constraints explicitly. The result is the same numerical solution. In larger multibody systems, a carefully chosen combination or representation of constraints may be better conditioned than simply differentiating the original constraints directly.

  44. Maria

    Delay can also be combined with DAEs. If delayed terms are added to the pendulum's force equations, the solution remains on the unit circle because the algebraic constraint is still enforced, but the motion is no longer truly periodic and becomes asymmetric. Delay handling relies on storing accurate interpolated solution values from prior times, only as far back as needed, which can require substantial internal machinery and memory.

  45. Corey

    The history function for a delay equation matters greatly. Maple commonly assumes a constant value for the solution before time zero, but that may not match the physical situation. A nonconstant history, such as an exponential function, can be represented by modifying the formulation with a piecewise term. Comparing a constant history with a varying history shows that the early-time behavior can be quite different.

  46. Maria

    For PDEs, the one-dimensional reaction-diffusion example uses Maple's native numerical PDE solver. Two concentrations, U of x and t and V of x and t, diffuse with separate coefficients and interact through reaction terms. The solution can be plotted at a chosen time, shown in three dimensions over space and time, or followed at a fixed spatial point.

  47. Corey

    The fixed-point plot can reveal behavior that is easy to miss. U may appear to approach its equilibrium concentration of six, but it can briefly pass below six and then rise again. That overshoot may suggest that the model's assumptions deserve further examination, perhaps because an additional modeling term is needed.

  48. Maria

    Native PDE support is not the same as the method of lines. The one-dimensional PDE solver described here uses a full finite-difference discretization. For a two-dimensional heat equation, Maple can instead use the method of lines: discretize the spatial variables with finite differences, then use dsolve numeric to integrate the resulting system of ordinary differential equations.

  49. Corey

    For the two-dimensional heat equation on a unit square, choose an n plus one by n plus one grid. The second spatial derivative is approximated by the standard centered finite-difference formula, using the value at a grid point and its four neighboring points. The boundary values are fixed directly, and the interior grid values become the unknown functions of time.

  50. Maria

    With n equal to twenty, the grid has twenty-one points in each direction and a little over four hundred grid locations, although the boundary values are already known. The initial condition is assigned at the interior points, and the finite-difference equations, boundary conditions, and initial conditions are passed to dsolve numeric. The numerical output can then be reorganized into a matrix and displayed as a three-dimensional surface.

  51. Corey

    That matrix-based setup makes it easy to inspect the initial surface, evaluate the solution later, and animate the heat equation as it evolves. At a later time such as one quarter, the surface has the same general shape but reduced height, reflecting diffusion. The same strategy can be extended to three spatial dimensions, but the number of equations grows rapidly: a twenty-by-twenty-by-twenty grid already involves roughly twenty cubed unknowns.

  52. Maria

    Efficiency in constructing these large equation sets matters. Using seq, rather than repeatedly appending inside a for loop, avoids creating intermediate data structures. A loop that grows a set one item at a time can have a cost that grows quadratically with the number of items, while seq can construct the final structure directly.

  53. Corey

    Finally, Maple provides a programmer interface for dsolve. This is useful when the model contains something that prevents direct input, such as an integral, or when you want to generate a large system programmatically. You convert the equations to a first-order vector system, create a procedure that evaluates the right-hand side, and let that procedure call other Maple functionality as needed.

  54. Maria

    The procedure form is flexible: it can call complicated Maple operations, including integration routines, although compilation may not work when the procedure calls sufficiently complicated code. It is also a practical alternative for method-of-lines problems, because a short procedure can loop over grid points and calculate the needed values instead of explicitly constructing a huge collection of equations.

  55. Corey

    So the overall picture is broad. Use dsolve numeric for ordinary initial and boundary value problems, choose Taylor methods for demanding accuracy and stiff methods for stiff systems, use events and discrete variables for state changes, and combine parameters with compilation for repeated solves.

  56. Maria

    For harder boundary value and eigenvalue problems, use continuation, shooting, or carefully chosen initial approximations. For DAEs, rely on Maple's prolongation-projection machinery and explicit constraints when needed. For delays and PDEs, pay close attention to history functions, discretization, output organization, and the growing computational cost of higher dimensions.

  57. Corey

    And when the standard input form is not enough, the programmer interface, array output, piecewise representations, and direct plotting tools give you ways to build a workflow around the numerical solver. The key is not just obtaining a numerical answer, but choosing a formulation and numerical method that fit the problem's accuracy, stiffness, events, constraints, parameters, and geometry.

  58. Maria

    That gives us the complete toolkit covered in this episode: Maple's numerical ODE, DAE, delay, and PDE facilities, along with interactivity, optimization, eigenvalue techniques, continuation, method-of-lines discretization, and programmer-level control. With the worksheet as a starting point, each example can be modified into a problem of your own and explored further.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent