Assignment 1

Part 3

In this part of the assignment you will improve the program you wrote in the previous section by changing the plotted output from points to lines showing trajectories in the phase plane.

1) In the last section of this assignment you determined the position in phase space of each ODE at each time step. You then plotted all the resulting points every time you took a step. To plot the trajectories of the ODEs in phase space you will need more information at each time step. You will not only need to determine the position in phase space of the ODE at that time step but you will also have to save the position at the last time step so that you can draw a line between the last position and the current position.

You will modify your code by adding a third axis to the arrays that hold the state variables (x and y). Make this new axis the first one and give it a NEWS layout and an extent of two. This will allow you to store the previous values of the state variables of the ijth ODE in the array elements x(1, i, j) and y(1, i, j) and the current values in x(2, i, j) and y(2, i, j). Start by modifying the declarations of x and y in the main program (file phaseplot.fcm).

2) In the routine set_initial_conds you will now want to initialize the values of x(1, i, j) and y(1, i, j) for all values of i and j. You can do this by passing the appropriate array section into set_initial_conds when you call it from the main program. The code in set_initial_conds will not have to be modified.

3) The routine that updates the state variables every time you take a step (routine "step" in file solver.fcm) will have to be modified. You should pass in the entire x and y arrays and update x(2, i, j) and y(2, i, j) based on the values of x(1, i, j) and y(1, i, j) (the values saved from the previous time step). Don't forget to change the declarations in the routine as well as the code that does the updating.

4) Next you should add a new routine called plot_lines to the file plot.fcm. It will be similar to plot_points so you can use your text editor to make a copy of plot_points and then edit the copy. The arguments passed to plot_lines will be the same as those passed to plot_points so you need only change the word "points" to "lines" to correct the call from the main program. Within plot_lines you will have to modify the declarations of x, y, int_x, and int_y. The code that transforms the state variables into pixel coordinates will not have to be changed. You will simply be transforming both the previous and the current state variables at the same time. Finally, you have to make a call to a routine that plots lines instead of points. Use CMview to find the appropriate routine in the CMX11 Reference Manual. Using the information in the manual, change the call to CMXDrawPoint to a call to the a routine that will plot lines connecting the previous values of the state variables to the current values.

5) You have one final task. At the bottom of the DO loop in the main program add code that will store the current values of the state variables in the locations reserved for previous values before beginning the next iteration of the loop.

If you have successfully completed all five steps you should be able to run your code and see the trajectories of the ODEs plotted as your program steps through their solutions. It should be much easier for you to see how the dynamical system behaves than it was when you were only plotting points.

Go back to part 2.
Continue to part 4.
Return to the class home page.