Question: please solve all my doubts, will rate a good answer solution is provided 9. Design patterns and interfaces: A class Minimiser is a class for

please solve all my doubts, will rate a good answer
solution is provided
please solve all my doubts, will rate a good answer solution is
provided 9. Design patterns and interfaces: A class Minimiser is a class
for finding the minimum of a real-valued, univariate function f(x) (using a
particular minimisa- tion algorithm e.g. Newton-Raphson). Its public interface is defined as
follows: class Minimiser { explain the meaning public: Minimiser (const Func& f,

9. Design patterns and interfaces: A class Minimiser is a class for finding the minimum of a real-valued, univariate function f(x) (using a particular minimisa- tion algorithm e.g. Newton-Raphson). Its public interface is defined as follows: class Minimiser { explain the meaning public: Minimiser (const Func& f, const double startx); double Minimum() const; double MinimumLocation () const; private: Func _f; double startX; double _minimum; double _minimumX; The user supplies a class derived from the base class Func which can compute the value of the function at a point, and possibly its derivative at that point. The constructor first checks if the function can compute the derivative, and then finds the local minimum, starting from the x value startX (don't concern yourself with the details of this algorithm, other than to note that it must either use the user-supplied derivatives or compute them numerically). (a) Design the interface for the base class Func. (b) Write the skeleton of a class for the function e"/r? and describe the im- plementation steps required to find the minimum of the function using the Minimiser class. 9 1 Q2 2 class Func { public: Func() { } 3 3 is it a constructor? 4 Func(const Funck d) { Sis it a constructor? } 6 7 8 9 10 11 12 13 virtual bool hasDerivative () const { return false; } Qs what does return fake" mean virtual double val (double x) const { return 0.0 } 24: why we have 2 double here? virtual double derivative (double x) const { return 0.0; } 14 16 17 IN 30 21 Os please explain }; Listing 14: Func interface Above is an example of how the base class for a function to be optimised might be specified. What this base class does is to define a well specified interface between the minimiser code and the user-supplied code. Below is an example of a specific instance of a function to minimise, inheriting from Func so that it can be used by the minimiser class. 1 2 class e_x_x_squared: public Func { public: e_x_x_squared () { } 14 10 11 e_x_x_squared (const Funck b) { } bool hasDerivative () const { why return true; > Q6: Vetum true" here? } double val(double x) const { return exp(x)/( xx); ) double derivative (double x) const { W a nice derivative calculator exists at http://www. derivative-calculator.net/ return exp(x)/(x x) - 2 exp(x) / (x * *); 12 15 16 17 IN 19 20 Listing 15: $ To find the minumum, the programmer would instantiate the ExpOverXSquared class, and instatiate the Minimiser class W a good set of references for Newton-Raphson 13 W 1) http://www.stat. vanhington.edu/dobra/classes/536/Files/week/ newtonfull.pdf 1/ 2) http://en.wikipedia.org/wiki/Newton 127_eethod_in_optimization 10 lo clasa Minimiser public: W the constructor does the work of finding the minimal value of a W function does not check second order conditions and 1 computes second derivative nuserically using W/ analytic first -- takes a Fanc (the 10 function to minimize) and W a starting value start in the domain of Func Minimiser (const Funck f, conat double startI): _f().start X (start) { 10 12 67: explain this line 3 IS 16 LT IS please explain 19 20 21 22 21 226 29 30 double X-startX: double precision - nuseric_lisits :: infinity(); int 10: if (f. hasDerivative () { in general while (precision> endingPrecision 1++ as 1 1 privato: Func_1: double startX: double minimum: double minimumx: 3 156 57 155 59 SO 2 double dx - 0.0001; double endingPrecision = 0.001; double stepSize = 0.1; int maxIters = 1000000; }; Listing 16: Minimiser class with this object as follows: #include "Minimiser.h" int main() { e_x_x_squared func; Minimiser (func, 10); } Listing 17: Minimiser use The minium and its location can then be returned using m. Minimum(); m. MinimumLocation (); Listing 18: The Answer 3 4 5 6 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!