Math 157: Assignment 2

Assigned Monday Jan. 9, 2009, due Friday, Jan. 16, 2009


Theory Work

[1] Read Chapters 3 in Blaha & Rumbaugh.

[2] The program EulerMethod1Dtest.cpp used in computational problem (a) relies on a class structure implemented in the files EulerMethod1D.h, EulerMethod1D.cpp, DoubleFunction1D.h and TestODE1D.h. From these files, create a detailed class diagram corresponding to the class structure they implement. (Documentation for the classes in these files can be viewed by opening the link index.html in the Doc subdirectory of the download directory.)

[3] Given the the following "high level" class structure used for a program to compute solutions to systems of ODE's using Euler's method:

EulerMethod

create a detailed class diagram (e.g. specify attributes and operations) based upon it that provides the class structure required to solve the systems of equations that are implemented as classes that extend (are derived from) the VectorFunction class.

For the DoubleVector class in this diagram, you need only specify the requisite operations associated with the class that are needed for it's use in the construction of a program to numerically solve systems of ODE's. You do not need to specify attributes. Since you will be implementing this class structure in computational problem (b), you should use the names of operations that are used in the implementation of DoubleVector class.

[4] (a) Verify that $(y_1(t),\, y_2(t))\, =\, (\mathrm{sin}(\omega t), \, \mathrm{cos}(\omega t)$) is a solution of the two dimensional initial value problem
$\qquad \qquad \begin{array}{rrl}
\dfrac{\mathrm{d}y_1}{\mathrm{d}t} & = & \; \;\omega \, y_2 \;\;\;\;\;\;y_1(0)=0 \\ \, \\
\dfrac{\mathrm{d}y_2}{\mathrm{d}t} & = &-\omega \, y_1\;\;\;\;\;\;y_2(0)=1
\end{array}
$

(b) What two dimensional initial value problem does $(y_1(t),\, y_2(t))\, =\,(e^{-a t} \mathrm{sin}(\omega t),\, e^{-a t} \mathrm{cos}(\omega t)$) satisfy?

Computational Problems

(a) [i] Download the Assign2a files from the repository Assign2aFiles located at https://www.math.ucla.edu/~anderson/157support/ $\,\,$Note that this link starts with https, not http. There are two ways to obtain the files from the repository, either by using the Mercurial command hg or by going to the web page and downloading the .gz or .zip file (Obtaining Math 157 Repository Files). The download consists of a directory containing .h and .cpp files as well as a subdirectory, Doc, containing class documentation.

[ii] Copy the Assign2a files to a directory (I suggest calling it Assign2a) and create a project to compile and link the files into an executable. For Visual Studio users, you may want to create a Win 32 console project first and then copy the Assign2a files into the project directory.

The test program as it is originally constructed solves the initial value problem

$\qquad \dfrac{\mathrm{d}y}{\mathrm{d}t} \, = \, y \qquad y(0) = 1 $

for $t \in [0,2]$ and reports the solution and the error at time $t=2$. Verify that the program runs.

[iii] Create a class ODE2a that extends the DoubleFunction class and implements the function corresponding to the right hand side of the ODE

$\qquad \dfrac{\mathrm{d}y}{\mathrm{d}t} \, = \, 5 \, \mathrm{cos}(y) \qquad y(0) = 0 $

This class should be declared and implemented in the file named ODE2a.h

[iv] Modify the main routine in EulerMethod1Dtest.cpp to solve the initial value problem in [iii] up to time $t = 5$. Name the executable Assign2a.exe. When Assign2a.exe is run, the program should output the approximate value of the solution at time $t = 5.0$.

(b) [i] Download the files for the DoubleVector class from the repository DoubleVector located at https://www.math.ucla.edu/~anderson/157support/ $\,\,$ It is suggested that you either clone or download these files to a directory called DoubleVector.

[ii] Using the DoubleVector class that you downloaded, create an implementation of the class structure to solve systems of equations using Euler's method that you created in theory problem [3]. For the EulerMethod class implementation, the class should be declared in the header file EulerMethod.h and the implementation of the operations (member functions) should be contained in the source file EulerMethod.cpp. The VectorFunction class should be declared in the header file VectorFunction.h.

[iii] Create a test code that solves the initial value problem of the two-dimensional system of ODE's of theory problem [4](a) with $\omega = 1.0$ up to time $t = 10.0$. For this problem, specify the ODE by creating a class called OscillatorODE that extends the VectorFunction class. This class should be defined and implemented in the file OscillatorODE.h. Your test code (which will be analogous to that used for the one dimensional ODE of problem (a)) should prompt the user for the number of timesteps, compute the solution and then print out each component of the numerical solution at $t=10$ and the error in each component of the solution at $t = 10$. Name the executable for this program Assign2b.exe.

What You Should Turn In


Items to be turned in in class: