Math 157: Assignment 4

Assigned Friday, Jan. 23 2009, due Friday, Jan. 30, 2009

What You Should Turn In


Written Problems

[1] Our target application is one that will allow a user to specify and then view solutions of systems of ODEs. This application can be decomposed into two subsystems, a subsystem for user interface/output display, and a subsystem for computing the approximate solution to the ODEs. To facilitate this decomposition, a class is needed that binds together the functionality of the ODE solution classes you have constructed and provides a programming interface to the ODE solver subsystem. Design and then create a class diagram for a class ODEsolver that satisfies this requirement. This ODEsolver class should:

Your class diagram should include the designation of associations with your existing ODE solver classes.

[2] Short answer questions:

(i) One way of including header (.h) files that are located in "other" directories is to include full path specifications to the header files. For example, an include statement could be of the form
#include "Z:\157courseDirectory\CAMsymfun\symfun.h"
Why should this construction be avoided?

(ii) If one has a main() routine that depends upon a class classA, beginning programmers will include both the header and the source in the main() routine file, e.g. they will use a construct in main.cpp of the form

#include "classA.h"  
#include "classA.cpp" 
int main(...)
Give two good reasons why this is programming construct should not be used.


(iii) What effect does the input step size have on the accuracy of the solution computed with a RKF45 method? (You'll answer this question after completing computational problem (c)).



Computational Work

[Preliminaries] To do this assignment you will need to download the RKF45 repository from https://www.math.ucla.edu/~anderson/157support/ .

(a) The RKF45 repository contains a class RKF45method that implements the RK45Fmothod class diagram. For computational efficiency reasons, this class does not have the same interface as your EulerMethod class. In particular, the advance(...) member function behaves differently. When incorporating this class into your existing class structure, you have the choice of changing your EulerMethod class and test codes to conform to the RKF45method interface and behavior, or you can create a "wrapper class" for the RKF45method that provides an interface and behavior that is coincident with your existing EulerMethod class.

Create a test code, based on the test code from Assignment 3(b), that uses the RKF45method. In addition to the parameters already prompted for, your test code should also prompt the user for the required tolerance parameter.

(b) Create the ODEsolver class you designed in written problem [1].

(c) Create a "console based" user interface test program that assumes an initial condition of $(x,y) = (1.0,0.0)$ and prompts the user for

The program should then use an instance of your ODEsolver class to compute the solution. The program should extract from the ODEsolver instance the solution times and solution data values. These values should be printed to file called odeOutput.dat where each line contains the output time and the values of the two solution components at this time (the values on each line should be separated by spaces).

If you want to view your solution, the data in this output file can be viewed using Gnuplot or loaded into Matlab or Excel and then plotted. In Gnuplot, to view both components in one plot, cd to the directory containing the data and use a command of the form

gnuplot>plot "odeOutput.dat" using 1:2 title 'X(t)',"odeOutput.dat" using 1:3 title 'Y(t)';


What You Should Turn In

In an Assign4 subdirectory of your submit directory, place