Classroom Tips and Techniques: SliderControl of Parameters in Numeric Solutions of ODEs
Robert J. Lopez
Emeritus Professor of Mathematics and Maple Fellow
Maplesoft

Introduction


In the article "Sliders for ParameterDependent Curves," and again in the article "Caustics for a Plane Curve," the use of sliders to control parameters was explored. This month's article explores the use of sliders to control parameters in a differential equation that must be solved numerically.
The differential equation governing the motion of a damped linear oscillator contains at least two parameters, the damping coefficient and the spring constant. Sliders are easily implemented for visualizing the effect of these parameters because the equation can be solved analytically. The essence of month's article is the implementation of sliders to control parameters in an ODE that must be solved numerically.


Initializations


The following modifications to the input/output protocol for differential equations allow a more natural notation. For a full discussion of these devices, see the Classroom Tips and Techniques article Notational Devices for ODEs.


The Damped Oscillator


The ODE governing the motion of a damped (and driven) linear oscillator is taken as
 (1) 



and the inert initial conditions
 (2) 



are assumed. Note that the driving term has been included, making the differential equation nonhomogeneous. This choice for the driving term implies that the solution becomes unbounded when the parameters assume the values a = 0, b = 1. Resonance also occurs when . However, the solution remains bounded in this case.


Analytic Solution


Maple represents the analytic solution of the initial value problem comprised of (1) and (2) as
Table 1 lists the fundamental set (solutions of the homogeneous ODE) for different regimes for the parameters a and b.
Fundamental Set

Parameter Regime









Table 1 Fundamental set for different parametervalue regimes



The parameterdependence of the particular solution is given by
It is no surprise, then, that the analytic solution is undefined if is one of the pairs , . Where the "form" of the solution changes, divisionbyzero errors are generated under simple evaluation in Maple.


SliderControl of Parameters for the Analytic Solution


The following code will launch the Interactive Parameter Maplet in which the graph of the solution is under the control of two sliders that vary the values of the parameters a and b.
Figure 1 is a screenshot of the Interactive Parameter Maplet.

Figure 1 Solution of the damped oscillator for one set of parameter values



Applying the evalc command to dramatically improves the performance of the Interactive Parameter Maplet. Without it, the performance of the Maplet degrades significantly.
Had the Plot Builder been invoked on the expression for , the same Interactive Parameter Maplet could have been been generated "interactively." However, the expression for , is very large, expanded in part because of the many instances of the signum function applied to .


SliderControl of Parameters for a Numeric Solution


Maple's dsolve/numeric command writes a procedure that only initiates computations when called. This procedure can have provision for symbolic parameters. For example, graphs of the numeric solution for several sets of parameter values can be generated by the following code.
The inclusion of the compile option considerably speeds up the ensuing numeric calculations. Additionally, it is possible to write a procedure that passes parameter values to the numeric procedure in a "continuous" fashion. The following code shows how this might be done.
The interactiveparams command can now be applied to the function with the same output that was obtained for the analytic solution.
Figure 2 contains a screenshot of the resulting Interactive Parameter Maplet.

Figure 2 Interactive Parameter Maplet serving a numeric solution of the initial value problem containing two parameters.





Parameter Control with a 2DSlider


Since there are only two parameters, it is possible to control the graph of the solution with a "2D" slider. The graph on the left in Figure 2 is a representation of the abplane. Dragging across this plane sends values of the pair to code that, on the right, graphs a numerical solution of the initial value problem (1) and (2). Be sure to begin by pressing the Initialize button under the graph on the right.
=

=


Figure 3 Parametercontrol via a "2D" slider



To see the codes that drive the application in Figure 3, rightclick (or its equivalent) on the Initialize button and select "Component Properties." In the dialog that opens, click "Edit". Then, rightclick on the lefthand graph, select "Component/Component Properties" and in the dialog that opens, click "Edit" opposite "Action When Dragged."

Legal Notice: © Maplesoft, a division of Waterloo Maple Inc. 2012. Maplesoft and Maple are trademarks of Waterloo Maple Inc. This application may contain errors and Maplesoft is not liable for any damages resulting from the use of this material. This application is intended for noncommercial, nonprofit use only. Contact Maplesoft for permission if you wish to use this application in forprofit activities.
