Assigned Friday, Jan. 16, 2009, due Friday, Jan. 23, 2009
Written Problems
[1] If $f : \mathrm{R} \to \mathrm{R}$ is a continuously differentiable function, then Newton's method for approximating solutions of $f(x)=0$ consists of the following iteration:
$\qquad \qquad x^0 =$ initial approximation
$\qquad \qquad x^{k+1} \,=\, x^{k} - \dfrac{f (x^k ) }{f' (x^k ) } \qquad $ for $k=1 \ldots $
(i) Create a class model that describes the class structure that could be used to provide components for the creation of a program that uses Newton's method to solve equations of the form $f(x)=0$. In your class model, you should use complete UML2 modeling notation, and, in particular, specify association properties in your model (names, multiplicity, etc) as appropriate.
(ii) Construct and turn in a pseudo-code program that utilizes your class structure to approximate a root of $x-tan(x) = 0$ starting from an initial value $x = 1.0$.
[2] Describe the changes in the class model presented in [1] that would be required if the target problem consisted of finding roots of polynomials with real coefficients.
[3] These questions refer to the test code and associated classes distributed for Assignment 2, computational problem (a).
(i) What happens if the keyword virtual is left out of the prototype for the evaluate member function in DoubleFunction1D.h?
(ii) What happens if the evaluate member function is no longer specified as pure virtual function in DoubleFunction1D.h, e.g. it is specified as
virtual double evaluate(double y){return 0.0;};
(iii) What happens if the keyword virtual is left out of the prototype in (ii), e.g. in DoubleFunction1D.h evaluate is specified as
double evaluate(double y){return 0.0;};
(iv) What happens if the the evaluate member function in DoubleFunction1D.h is defined as in (ii) and in the implementation and use of the advance member function of EulerMethod1D, the DoubleFunction1D argument is passed by value, e.g.it has the prototype
double EulerMethod1D::advance(double yk, double dt, DoubleFunction1D F)
![]()
Computational Work
[Preliminaries] To do this assignment you will need to download the CAMsymfun repository from https://www.math.ucla.edu/~anderson/157support/ . It is recommended that the directory structure of this repository be kept intact and to only have one copy of it on your local system. The directory of this repository contains both the header files and source files of the CAMsymbolic function class. To check your ability to incorporate these codes into a project, try building and then running an executable for the test program SymTest.cpp.
[a] Implement the class VectorSymbolicFunction2D that extends your VectorFunction class and utilizes the CAMsymbolicFunction class obtain its functionality, e.g. create the class as indicated in the attached class diagram.
The initialize(f1:string, f2:string) member function should accept two STL string instances in the variables x and y that specify the components of a function from $\mathrm{R}^2 \to \mathrm{R}^2$. When you implement VectorSymbolicFunction2D, you should have the initialize member function call the appropriate initialize(...) member function of the associated CAMsymbolicFunction instances. The initialize function should return 0 if the initialization was successful and a non-zero value otherwise.
[b] Using your VectorSymbolicFunction2D class from problem [a], create a main program that prompts a user for two functions in the variables x and y, and then returns the solution at T = 1.0 of the two dimensional ODE specified by those functions with an initial condition at t = 0 of (x,y) = (1,0). Specifically, a program that computes the solution to
$\qquad \dfrac{d x}{dt} \, = \, f_1(x, \,y) \qquad x(0)=1 $
$\qquad \dfrac{d y}{dt}\, = \, f_2(x, \,y) \qquad y(0)=0 $
for $t \in [0,1]$ where $ f_1(x, \,y) $ and $ f_2(x, \,y) $ are specified by the user at the command line.
In an Assign3 subdirectory of your submit directory, turn in
A summary of what your submit subdirectory Assign3 should contain:
VectorSymbolicFunction2D.h, VectorSymbolicFunction2D.cpp, Assign3.cpp, Assign3.exe