C++ main module for mmsd Package  1.0
MATH_Equation.h
Go to the documentation of this file.
1 #ifndef MATH_Equation_H
2 #define MATH_Equation_H
3 
4 
5 #include "UI_Object.h"
6 #include "UI_Class.h"
7 
8 #include "MATH_Function.h"
9 
10 
20 
21 class MATH_Equation: public virtual UI_Object {
22  SP_OBJECT(MATH_Equation);
23 
24  // ATTRIBUTES
25 
26 public:
27  static const tReal EPSILON;
28 
29 
30  /* - mMaxError : the max error
31  * - type: real
32  * - card: 1
33  * - mMaxIterationsNumber: the max number of iterations
34  * - type: integer
35  * - card: 1
36  * - mIterationsNumber: the number of iterations
37  * for having error les thass mError
38  * - type: integer
39  * - card: 1
40  * - mX: the value x to solve f(x)=0
41  * - type: tReal
42  * - card: 1
43  *
44  * - mError: the error on x
45  * - type: tReal
46  * - card: 1
47  *
48  */
51 
55 
57 
58  /* Associations:
59  * - mFunction which is the function f
60  * - type: MATH_Function
61  * - card: 1
62  */
63  WP::MATH_Function mFunction;
64 
65 private:
66 
67 
68 protected:
69  // METHODS
70 
71  // CONSTRUCTORS
72 
74  MATH_Equation(void);
75 
76 
77 
78  // DESTRUCTORS
79 
80 
83  virtual ~MATH_Equation(void);
84 
85 
86 public:
87 
88  // NEW methods
89 
90 
91 
92 
93  // COPY methods
96  virtual void copy(const MATH_Equation* m);
97 
98 
99 
100  //-------------------------
101  // SAVER & LOADER methods
102  // ------------------------
103 
104 public:
105 
106 
109  virtual void loadFromUIClass(const UI_Class& mclass);
110 
113  virtual void saveToUIClass(UI_Class& mclass) const;
114 
115 
116  // -----------------
117  // function setting
118  // -----------------
119 public:
122  virtual void setInterval(const tReal& a,const tReal& b) {
123  mInterval[0]=a;
124  mInterval[1]=b;
125  };
128  inline void getInterval(tReal& a,tReal& b) const {
129  a=mInterval[0];
130  b=mInterval[1];
131  };
132 
135  inline void setMaxIterationsNumber(const int& v) {
136  mMaxIterationsNumber=v;
137  };
140  inline int getMaxIterationsNumber() const {
141  return mMaxIterationsNumber;
142  };
145  inline tReal getSolution() const {
146  return mX;
147  };
150  inline int getIterationsNumber() const {
151  return mIterationsNumber;
152  };
155  inline tReal getError() const {
156  return mError;
157  };
160  inline void setMaxError(const tReal& err) {
161  mMaxError=err;
162  };
165  inline tReal getMaxError() const {
166  return mMaxError;
167  };
168 
169 protected:
172  inline void setSolution(const tReal& x) {
173  mX=x;
174  };
177  inline void setIterationsNumber(const int& n) {
178  mIterationsNumber=n;
179  };
182  inline void setError(const tReal& err) {
183  mError=err;
184  };
185 
186 public:
187 
190  inline void setFunction(SP::MATH_Function f) {
191  mFunction=f;
192  };
195  inline const MATH_Function* getFunction() const {
196  SPC::MATH_Function p=mFunction.lock();
197  return p.get();
198  };
202  SP::MATH_Function p=mFunction.lock();
203  return p.get();
204  };
205 
208  virtual tBoolean hasFunction() const {
209  return (getFunction()!=null);
210  }
211 
212  // -----
213  // solve
214  // -----
215 
218  virtual tReal solve()=0;
221  virtual tReal solve(const tReal& x0)=0;
222 
225  virtual tBoolean hasSucceeded() const {
226  return (mIterationsNumber<mMaxIterationsNumber+1);
227  }
228 
231  virtual tString toString() const;
232 
233  //Internal methods
234 private:
235 };
236 
237 
238 #endif
void setMaxError(const tReal &err)
set the wished max error
Definition: MATH_Equation.h:160
WP::MATH_Function mFunction
Definition: MATH_Equation.h:63
virtual void saveToUIClass(UI_Class &mclass) const
how to save the object from a mate model class
Definition: MATH_Equation.cpp:33
This class describes a function function.
Definition: MATH_Function.h:16
tReal mError
Definition: MATH_Equation.h:54
virtual tBoolean hasSucceeded() const
return true if the method has succeeded
Definition: MATH_Equation.h:225
DEFINE_SVPTR(MATH_Equation)
MATH_Function * getFunction()
get the function
Definition: MATH_Equation.h:201
This class is the base class of User Interface package.
Definition: UI_Object.h:23
This class describes the main interface class for a soft user interface (R,matlab,python etc...) class.
Definition: UI_Class.h:38
virtual ~MATH_Equation(void)
destroy an Equation Object.
Definition: MATH_Equation.cpp:19
tReal getSolution() const
get the solution
Definition: MATH_Equation.h:145
#define tBoolean
Definition: types.h:48
static const tReal EPSILON
Definition: MATH_Equation.h:27
virtual void copy(const MATH_Equation *m)
copy the parameters of the optimization method
Definition: MATH_Equation.cpp:44
#define null
Definition: types.h:13
void getInterval(tReal &a, tReal &b) const
get interval of searching
Definition: MATH_Equation.h:128
int getIterationsNumber() const
get the iterations number to reach the solution
Definition: MATH_Equation.h:150
DEFINE_SPTR(MATH_Equation)
virtual tString toString() const
to string
Definition: MATH_Equation.cpp:54
void setFunction(SP::MATH_Function f)
set function
Definition: MATH_Equation.h:190
virtual tReal solve()=0
solve the equation
tReal getError() const
get the error estimated with the solution
Definition: MATH_Equation.h:155
int mIterationsNumber
Definition: MATH_Equation.h:52
const MATH_Function * getFunction() const
get the function
Definition: MATH_Equation.h:195
This class solve the equation f(x)=0.
Definition: MATH_Equation.h:21
tReal mX
Definition: MATH_Equation.h:53
void setSolution(const tReal &x)
set the solution
Definition: MATH_Equation.h:172
void setError(const tReal &err)
set the error estimated with the solution
Definition: MATH_Equation.h:182
int mMaxIterationsNumber
Definition: MATH_Equation.h:50
#define tString
Definition: types.h:49
void setIterationsNumber(const int &n)
set the iterations number to reach the solution
Definition: MATH_Equation.h:177
tReal mInterval[2]
Definition: MATH_Equation.h:56
virtual void setInterval(const tReal &a, const tReal &b)
set the interval of searching
Definition: MATH_Equation.h:122
tReal mMaxError
Definition: MATH_Equation.h:49
virtual tBoolean hasFunction() const
return true if the optimized method has function
Definition: MATH_Equation.h:208
#define tReal
Definition: types.h:18
void setMaxIterationsNumber(const int &v)
set max iterations number
Definition: MATH_Equation.h:135
MATH_Equation(void)
create a Equation object
Definition: MATH_Equation.cpp:7
tReal getMaxError() const
get the wished max error
Definition: MATH_Equation.h:165
virtual void loadFromUIClass(const UI_Class &mclass)
how to load the object from a Meta Model class
Definition: MATH_Equation.cpp:23
int getMaxIterationsNumber() const
get the max iteration number
Definition: MATH_Equation.h:140