solution.h
Go to the documentation of this file.
1 
6 
7 #include "myexcept.h"
8 
9 #ifdef use_namespace
10 namespace RBD_COMMON {
11 #endif
12 
13 
14 // Solve the equation f(x)=y for x where f is a monotone continuous
15 // function of x
16 // Essentially Brent s method
17 
18 // You need to derive a class from R1_R1 and override "operator()"
19 // with the function you want to solve.
20 // Use an object from this class in OneDimSolve
21 
22 class R1_R1
23 {
24  // the prototype for a Real function of a Real variable
25  // you need to derive your function from this one and put in your
26  // function for operator() at least. You probably also want to set up a
27  // constructor to put in additional parameter values (e.g. that will not
28  // vary during a solve)
29 
30 protected:
31  Real x; // Current x value
32  bool xSet; // true if a value assigned to x
33 
34 public:
35  Real minX, maxX; // range of value x
36  bool minXinf, maxXinf; // true if these are infinite
37  R1_R1() : xSet(false), minXinf(true), maxXinf(true) {}
38  virtual Real operator()() = 0; // function value at current x
39  // set current x
40  virtual void Set(Real X); // set x, check OK
41  Real operator()(Real X) { Set(X); return operator()(); }
42  // set x, return value
43  virtual bool IsValid(Real X);
44  operator Real(); // implicit conversion
45  virtual ~R1_R1() {} // keep gnu happy
46 };
47 
49 {
50 public:
51  static unsigned long Select;
52  SolutionException(const char* a_what = 0);
53 };
54 
56 {
57  R1_R1& function; // reference to the function
58  Real accX; // accuracy in X direction
59  Real accY; // accuracy in Y direction
60  int lim; // maximum number of iterations
61 
62 public:
63  OneDimSolve(R1_R1& f, Real AccY = 0.0001, Real AccX = 0.0)
64  : function(f), accX(AccX), accY(AccY) {}
65  // f is an R1_R1 function
66  Real Solve(Real Y, Real X, Real Dev, int Lim=100);
67  // Solve for x in Y=f(x)
68  // X is the initial trial value of x
69  // X+Dev is the second trial value
70  // program returns a value of x such that
71  // |Y-f(x)| <= accY or |f.inv(Y)-x| <= accX
72 
73 private:
74  Real x[3], y[3]; // Trial values of X and Y
75  int L,C,U,Last; // Locations of trial values
76  int vpol, hpol; // polarities
77  Real YY; // target value
78  int i;
79  void LookAt(int); // get new value of function
80  bool Finish; // true if LookAt finds conv.
81  bool Captured; // true when target surrounded
82  void VFlip();
83  void HFlip();
84  void Flip();
85  void State(int I, int J, int K);
86  void Linear(int, int, int);
87  void Quadratic(int, int, int);
88 };
89 
90 
91 #ifdef use_namespace
92 }
93 #endif
94 
95 // body file: solution.cpp
96 
97 
99 
virtual ~R1_R1()
Definition: solution.h:45
R1_R1()
Definition: solution.h:37
Real accX
Definition: solution.h:58
bool minXinf
Definition: solution.h:36
OneDimSolve(R1_R1 &f, Real AccY=0.0001, Real AccX=0.0)
Definition: solution.h:63
bool xSet
Definition: solution.h:32
bool Finish
Definition: solution.h:80
Matrix K
Definition: demo.cpp:228
double Real
Definition: include.h:307
Real minX
Definition: solution.h:35
int vpol
Definition: solution.h:76
Real operator()(Real X)
Definition: solution.h:41
Definition: solution.h:22
Real x
Definition: solution.h:31
Real YY
Definition: solution.h:77
static unsigned long Select
Definition: solution.h:51
bool Captured
Definition: solution.h:81
Real accY
Definition: solution.h:59


kni
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:16