Tip 94. Program debugging and animation

Fig. 94. Program debugging and animation

The program RK4 of the solution an ordinary differential equation (Cauchy problem) by Runge-Kutta method of 4-th level is showed in the fig. 94. Some operators (four operators in loop body for) are united for more compactness in the program: (see tip 33). The program is tested on such problem: (t) = x+x2/t3 on the segment (0) = 1 and (7) = ?.

To look at the variation the values of all local variables of the program RK4 we can as have been recommended in tip 93 to write the variable values in arrays and to look through them after execution of the program. But it is possible to do it another way: to look through the values of the local variables during execution of the program but not after! For this it will be useful resources of animation of Mathcad.

Fig. 94a. On-line-program of Runge-Kutta method

The program RK4 modified in such directions is showed in the fig. 94:

The streamlined program RK4 returns the values of all local variables given value the variable FRAME by user.

Fig. 94b. Forming of animation filmloop

It is known that the variable FRAME serves for creation animation filmloops and is the counter of frames. The process of forming the animation with help of dialogue window Animate that is called by the same name command from the menu View is showed in the fig. 94b. At that user points out:

         initial and last value of the variable FRAME (in our case they equal 0 and 100);

         speed with that the animation will be showed (in our case it equals three shots per second);

         the area of Mathcad-document by which the animation is created (in our case it is showed by dotted rectangle: user has enveloped in changing part of the matrix with commentaries by broach).

After the keystroke Animate of the same name the dialogue window in the fig. 94b 101 frame of the animation will be written: the values of the local variables n, t, k1, k2, k3, k4 and at different values of the variable FRAME.

Fig. 94c. The animation filmloop during the program debugging

This animation filmloop is showed in the fig. 94. It can be saved on the disk as avi-file. We can call it by press down Videofilmloop (see fig. 94). Moving the slider of the player of the video-filmloop we can make the program RK4 to work to all directions to increase and decrease the value of the variable n. It allows to lock in some mistake easily it was done during creation of the program.