Recently, I received an email from a physics instructor asking for help in building a tool that would display the solution of the initial value problem 

 

with the four parameters under the control of sliders. (Of course, we recognize that this equation governs the damped, driven linear oscillator, and that the request to endow its solution with sliders is in service of visualization of the change in the nature of the solution as the parameters vary.) 

 

That very day I provided two solutions, the first, an interactive solution using the inert initial conditions and the Plot Builder (equivalent to using the command); and the second, using the general initial conditions , and embedded components. 

 To obtain the first answer to the email, I first obtained the general solution to the IVP (inert initial conditions). This can be done interactively from the Context Menu, which, through the option "Solve DE Interactively," launches the ODE Analyzer Assistant. This built-in tool for interactive solutions of both the IVP and the BVP (boundary value problem) can be launched from the Tools/Assistants menu, but accessing it from the Context Menu for the ODE itself saves typing the equation into the Assistant. 

Figure 1 shows the Assistant with the captured ODE.  

Image 

Figure 1   The ODE Analyzer Assistant launched from the Context Menu for an ODE 

 

 Clicking on the Edit button in the "Conditions" section launches the dialog box shown in Figure 2. 

Image 

Figure 2   Interactively adding initial conditions in the ODE Analyzer Assistant 

 

 In the "Add Condition" section at the top, zero is entered for the initial point, and for the value of at that point. Clicking the "Add" button enters that initial condition.  The drop-down box in this section also displays and the inert initial condition is entered for that, too. Clicking "Done" results in Figure 3.  

Image 

Figure 3   The ODE Analyzer Assistant after the addition of initial conditions 

  

Since the ODE contains four parameters, it would not be possible to solve the IVP numerically without specifying values for these parameters.  Instead, we select "Solve Symbolically," resulting in the display shown in Figure 4. 

 

 

Image 

Figure 4   The ODE Analyzer Assistant after selecting "Solve Symbolically" 

 
Clicking the "Solve" button generates the solution shown in Figure 5. 

Image 

Figure 5   Analytic solution of IVP provided by ODE Analyzer Assistant 

  Upon quitting the Assistant, the default return is this solution, written now without the abbreviation : 


`+`(`/`(`*`(exp(`*`(`+`(`-`(`*`(`/`(1, 2), `*`(c))), `*`(`/`(1, 2), `*`(`^`(`+`(`*`(`^`(c, 2)), `-`(`*`(4, `*`(k)))), `/`(1, 2))))), `*`(t))), `*`(A, `*`(`+`(`-`(`*`(c, `*`(`^`(`+`(`*`(`^`(c, 2)), `-`...
`+`(`/`(`*`(exp(`*`(`+`(`-`(`*`(`/`(1, 2), `*`(c))), `*`(`/`(1, 2), `*`(`^`(`+`(`*`(`^`(c, 2)), `-`(`*`(4, `*`(k)))), `/`(1, 2))))), `*`(t))), `*`(A, `*`(`+`(`-`(`*`(c, `*`(`^`(`+`(`*`(`^`(c, 2)), `-`...sol
 

Since this is in the form of an equation , we use the Context Menu to select the right-hand side, assign this right-hand side the name "sol," then again use the Context Menu to launch the Plot Builder. (The assigned name is used later where we create the same object with a Maple command.) See Figure 6 for the Plot Builder. 

Image 

Figure 6   Plot Builder used to generate an interactive plot with 4 parameters 


The display in Figure 6 is obtained by selecting "Interactive Plot with 4 parameters" in the "Select Plot Type and Functions" section, leaving "2-D plot" in the "Select Plot" section, and organizing the independent variable and parameters as shown in the "Select Variable Purposes, Ranges, and Plot Options" section.  Experience suggests the value of clicking on the "Options" button, and setting the vertical range for all graphs to be drawn by this tool. The Options panel is shown in Figure 7. 

Image 

Figure 7   The Options dialog in the Plot Builder 

The bounds on the vertical axis are set in the "Range from" section. Clicking on the "Plot" button produces the object shown in Figure 8. Had the vertical axis not been given fixed bounds, the graphs drawn by moving the sliders would have been rescaled to fill the Plot Window, making it difficult to discern some of the changes to the graphs so generated.  

Image 

Figure 8   Screen Capture of the Interactive Parameter Maplet generated by the Plot Builder 

  The object in Figure 8 is actually a Maplet, which means it cannot be saved independently. It is the active window, and the only way to move past this window is to close the Maplet. 

The default value of each slider is the midpoint of its initial range. Moving a slider does not change the graph continuously. The new graph is visible only when the slider is released in its new position. (This has been fixed in the upcoming version of Maple!) 

 The object displayed in Figure 8 can actually be generated by a call to the interactiveplots command from the plots package. Executing the following command will generate exactly the same object that is displayed in Figure 8. 

 

 There are two significant issues with this first answer to the question posed by the email message I received.  First, the object in Figure 8 cannot be saved. Once it is used, it must be "put away" to regain access to Maple. Second, building  the Maplet from the general solution of the IVP fails to account for the "repeated-root case," that is, the case when . Although the pixels on the typical screen might not ever allow this case to be sent to the expression captured in the name sol, it is still a glaring omission to neglect it. Hence, even as this first solution was being prepared (interactively, and quickly), it was clear that a solution based on Embedded Components would be much more satisfying. 

Table 1 contains the Component-based solution to the problem posed by my email. It successfully resolves shortcomings of the solution shown in Figure 8. First, the IVP is solved for user-determined initial conditions. Hence, there are now six sliders instead of four. Second, as a slider is moved, the graph updates continuously. Third, the object in Table 1 is part of the worksheet, and does not disappear after use. Fourth, there is active control of the horizontal and vertical axes.   

  

Embedded component 

Embedded component = 2 

Embedded component = 5 

Embedded component = 8 

Embedded component = 3 

Embedded component = 4 

Embedded component = 5 

15            -88

Table 1   Component-based tool for interactively graphing solutions of the driven damped oscillator 

The code behind a slider is extremely naive. The values of all the sliders are read, the appropriate IVP is formed, and then solved analytically by Maple's dsolve command. The resulting analytic solution is then graphed. Actually, the first implementation of this tool used numeric solutions of the IVP, but these proved to be more difficult to graph for some parameter ranges where more points than the default seemed to be needed to get smooth curves. So, the second implementation used symbolic solutions, with the proviso that if the process proved to be too slow, additional coding tricks would be needed.  These "tricks" would involve defining a solution procedure outside the bounds of the components, and then issuing function calls to it inside the sliders. However, I was delightfully surprised at the speed of Maple's symbolic engine - behind each slider I was able to use variants of the code behind the first slider, displayed in Table 2.  

use DocumentTools, plots in

module()local c,k,A,b,u,v,q,S,p,T,Y1,Y2;

Do(c = %Slider0);
Do(%Label0(caption) = c);

Do(k = %Slider1);
Do(A = %Slider2);
Do(b = %Slider3);
Do(u = %Slider4);
Do(v = %Slider5);
Do(T = %MathContainer0);
Do(Y1 = %MathContainer1);
Do(Y2 = %MathContainer2);

q := diff(y(t),t,t) +c*diff(y(t),t)+k*y(t)=A*cos(b*t);
S := dsolve({q,y(0)=u,D(y)(0)=v},y(t));
p := plot(rhs(S),t=0..T,y=Y1..Y2);

Do(%Plot0 = p);

end module;
end use;
 

Table 2   Code behind the Edit field of the first slider in Table 1 

 

 All the code in the slider component is wrapped in a module so that all its variables can be made local to the component. Otherwise, all assignments made in a component would be global, making for a very fragile tool. As can be seen from Table 2, the code is straightforward. Each slider is read, with the slider's value being displayed in a Label component to the right of the slider. Once the parameters are read, the IVP is formed and solved, and the solution is graphed for display in the Plot component. 

The physics instructor who asked how to build such a tool had both solutions in his hands before the end of the day on which I received the question. It was a Friday afternoon, and when I got back on Monday morning, I found "words cannot say..." in my inbox, sent over the weekend, from Greece from whence the question came. 

 I guess the next thing to think about is devising a way to vary the class of driving terms. Recall that the given ODE is driven by a sinusoid, namely, by . Adding an input field for different functions is certainly possible, but then, if there are different parameters connected with each such function, the sliders would have to change accordingly.  However, since I was not asked for this feature, I will leave that to an interested reader to ponder.

Please Wait...