Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

SOLUTION.H Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

SOLUTION.H

Go to the documentation of this file.
00001 //Owner: Fred
00002 //$$ solution.h                      // solve routines
00003 
00004 //#include "boolean.h"
00005 #include "myexcept.h"
00006 
00007 #ifdef use_namespace
00008 namespace RBD_COMMON {
00009 #endif
00010 
00011     // Solve the equation f(x)=y for x where f is a monotone continuous
00012     // function of x
00013     // Essentially Brent's method
00014 
00015     // You need to derive a class from R1_R1 and override "operator()"
00016     // with the function you want to solve.
00017     // Use an object from this class in OneDimSolve
00018 
00020     class R1_R1 {
00021         // the prototype for a Real function of a Real variable
00022         // you need to derive your function from this one and put in your
00023         // function for operator() at least. You probably also want to set up a
00024         // constructor to put in additional parameter values (e.g. that won't
00025         // vary during a solve)
00026 
00027     protected:
00028         Real x;                                     // Current x value
00029         bool xSet;                                  // true if a value assigned to x
00030 
00031     public:
00032         Real minX, maxX;                            // range of value x
00033         bool minXinf, maxXinf;                      // true if these are infinite
00034         R1_R1() : minXinf(true), maxXinf(true), xSet(false) {}
00035         virtual Real operator()() = 0;              // function value at current x
00036         // set current x
00037         virtual void Set(Real X);                   // set x, check OK
00038         Real operator()(Real X) { Set(X); return operator()(); }
00039         // set x, return value
00040         virtual bool IsValid(Real X);
00041         operator Real();                            // implicit conversion
00042     };
00043 
00045     class SolutionException : public Exception {
00046     public:
00047         static unsigned long Select;
00048         SolutionException(const char* a_what = 0);
00049     };
00050 
00054     class OneDimSolve {
00055         R1_R1& function;                              // reference to the function
00056         Real accX;                                    // accuracy in X direction
00057         Real accY;                                    // accuracy in Y direction
00058         int lim;                                      // maximum number of iterations
00059 
00060     public:
00061         OneDimSolve(R1_R1& f, Real AccY = 0.0001, Real AccX = 0.0)
00062             : function(f), accY(AccY), accX(AccX) {}
00063         // f is an R1_R1 function
00064         Real Solve(Real Y, Real X, Real Dev, int Lim=100);
00065         // Solve for x in Y=f(x)
00066         // X is the initial trial value of x
00067         // X+Dev is the second trial value
00068         // program returns a value of x such that
00069         // |Y-f(x)| <= accY or |f.inv(Y)-x| <= accX
00070 
00071     private:
00072         Real x[3], y[3];                            // Trial values of X and Y
00073         int L,C,U,Last;                             // Locations of trial values
00074         int vpol, hpol;                             // polarities
00075         Real YY;                                    // target value
00076         int i;
00077         void LookAt(int);                           // get new value of function
00078         bool Finish;                                // true if LookAt finds conv.
00079         bool Captured;                              // true when target surrounded
00080         void VFlip();
00081         void HFlip();
00082         void Flip();
00083         void State(int I, int J, int K);
00084         void Linear(int, int, int);
00085         void Quadratic(int, int, int);
00086     };
00087 
00088 #ifdef use_namespace
00089 }
00090 #endif

Generated on Fri Aug 23 01:38:37 2002 for VirtualU by doxygen1.2.17