C++ main module for mmsd Package  1.0
MATH_NewtonEquation.h
Go to the documentation of this file.
1 #ifndef MATH_NewtonEquation_H
2 #define MATH_NewtonEquation_H
3 
4 #include "CORE_Array.h"
5 
6 #include "MATH_Equation.h"
7 
8 #include "MATH_C1Function.h"
9 
20 
22  SP_OBJECT(MATH_NewtonEquation);
23 
24  // ATTRIBUTES
25 
26 public:
27 private:
28 
29 
30  tReal mdx;
31  tReal mXMin;
32  tReal mXMax;
33 
34 
35 private:
36 
37  // ASSOCIATIONS
38 
39 
40 protected:
41  // METHODS
42 
43  // CONSTRUCTORS
44 
46  MATH_NewtonEquation(void);
47 
48 
49 
50  // DESTRUCTORS
51 
52 
55  virtual ~MATH_NewtonEquation(void);
56 
57 
58 public:
59 
60  // NEW methods
61 
64  static SP::MATH_NewtonEquation New() {
65  SP::MATH_NewtonEquation p(new MATH_NewtonEquation(),
67  p->setThis(p);
68  return p;
69  };
70 
71 
72  // COPY methods
73 
76  virtual void copy(const MATH_Equation* m);
77 
78 
79  //-------------------------
80  // SAVER & LOADER methods
81  // ------------------------
82 
83 public:
86  virtual void loadFromUIClass(const UI_Class& mclass);
87 
90  virtual void saveToUIClass(UI_Class& mclass) const;
91 
92 
93 
94  // SET methods
95 
96 public:
99  virtual void setInterval(const tReal& a,const tReal& b) {
101  setConstraints(a,b);
102  };
103 
106  inline void setConstraints(const tReal& minX,const tReal& maxX) {
107  mXMin=minX;
108  mXMax=maxX;
109  };
112  inline void getConstraints(tReal& minX,tReal& maxX) const{
113  minX=mXMin;
114  maxX=mXMax;
115  };
116 
119  inline void setStep(const tReal& dx) {
120  mdx=dx;
121  }
122 
123 
124 
125 
126 
127 
128 
129  // GET methods
130 
131 public:
132 
133 
134 
135 
136 
137  // OTHERS methdos
140  virtual tReal solve();
143  virtual tReal solve(const tReal& x0) {
144  tReal error=0;
145  int iter=0;
146  tReal x=solveNewton(x0,error,iter);
147  setSolution(x);
148  setError(error);
149  setIterationsNumber(iter);
150  return x;
151  }
152 
155  virtual tString toString() const;
156 
159  virtual tBoolean hasFunction() const {
160  const MATH_C1Function *f=dynamic_cast<const MATH_C1Function*>(getFunction());
161  return (f!=null);
162  }
165  virtual tBoolean hasSucceeded() const {
167  succeeds = succeeds && (getError()<getMaxError());
168  return succeeds;
169  }
170 
171 private:
172  tReal solveNewton(const tReal& x0,tReal& error,int& iter);
173 
174 
175 
176 };
177 
178 
179 #endif
MATH_NewtonEquation(void)
create a NewtonEquation object
Definition: MATH_NewtonEquation.cpp:5
virtual tReal solve()
solve
Definition: MATH_NewtonEquation.cpp:38
This class describes a function of classe C1.
Definition: MATH_C1Function.h:17
virtual tBoolean hasSucceeded() const
return true if the method has succeeded
Definition: MATH_Equation.h:225
void setStep(const tReal &dx)
set the step
Definition: MATH_NewtonEquation.h:119
DEFINE_SVPTR(MATH_NewtonEquation)
virtual void loadFromUIClass(const UI_Class &mclass)
how to load the object from a Meta Model class
Definition: MATH_NewtonEquation.cpp:22
virtual tString toString() const
to string
Definition: MATH_NewtonEquation.cpp:34
void setConstraints(const tReal &minX, const tReal &maxX)
set the min & max constraints
Definition: MATH_NewtonEquation.h:106
This class describes the main interface class for a soft user interface (R,matlab,python etc...) class.
Definition: UI_Class.h:38
#define tBoolean
Definition: types.h:48
virtual ~MATH_NewtonEquation(void)
destroy an NewtonEquation Object.
Definition: MATH_NewtonEquation.cpp:16
This class solve the equation f(x)=0.
Definition: MATH_NewtonEquation.h:21
#define null
Definition: types.h:13
tReal getError() const
get the error estimated with the solution
Definition: MATH_Equation.h:155
const MATH_Function * getFunction() const
get the function
Definition: MATH_Equation.h:195
virtual void copy(const MATH_Equation *m)
copy the parameters of the optimization method
Definition: MATH_NewtonEquation.cpp:30
This class solve the equation f(x)=0.
Definition: MATH_Equation.h:21
virtual tBoolean hasFunction() const
return true if the optimized method has function
Definition: MATH_NewtonEquation.h:159
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
virtual tReal solve(const tReal &x0)
solve
Definition: MATH_NewtonEquation.h:143
#define tString
Definition: types.h:49
void setIterationsNumber(const int &n)
set the iterations number to reach the solution
Definition: MATH_Equation.h:177
static SP::MATH_NewtonEquation New()
create a copy of MATH_NewtonEquation
Definition: MATH_NewtonEquation.h:64
void getConstraints(tReal &minX, tReal &maxX) const
get the min & max constraints
Definition: MATH_NewtonEquation.h:112
virtual void setInterval(const tReal &a, const tReal &b)
set the interval of searching
Definition: MATH_NewtonEquation.h:99
virtual tBoolean hasSucceeded() const
return true if the method has succeeded
Definition: MATH_NewtonEquation.h:165
virtual void setInterval(const tReal &a, const tReal &b)
set the interval of searching
Definition: MATH_Equation.h:122
#define tReal
Definition: types.h:18
tReal getMaxError() const
get the wished max error
Definition: MATH_Equation.h:165
DEFINE_SPTR(MATH_NewtonEquation)
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
virtual void saveToUIClass(UI_Class &mclass) const
how to save the object from a mate model class
Definition: MATH_NewtonEquation.cpp:26