00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NONLINEAR_ALGEBRA_H_
00021 #define NONLINEAR_ALGEBRA_H_
00022
00023 #include "mbsim/utils/function.h"
00024 #include "fmatvec/fmatvec.h"
00025
00026 namespace MBSim {
00027
00028 enum SolverType {
00029 RegulaFalsiSolver, FixPointIterationSolver, NewtonMethodSolver
00030 };
00031
00037 class RegulaFalsi {
00038 public:
00039
00040
00041
00042
00043 RegulaFalsi(Function1<double,double> *f);
00044
00045
00046 int getNumberOfIterations() const { return it; };
00047 int getInfo() const { return info; };
00048 void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
00049 void setTolerance(double tol_) { tol = tol_; }
00050
00051
00057 double solve(double a, double b);
00058
00059 private:
00063 Function1<double,double> *func;
00064
00068 int itmax, it, info;
00069
00073 double tol;
00074 };
00075
00081 class MultiDimFixPointIteration {
00082 public:
00083
00084
00085
00086
00087 MultiDimFixPointIteration(Function1<fmatvec::Vec, fmatvec::Vec> *function_);
00088
00089
00090
00091
00092
00093
00094
00095
00096 int getInfo() {
00097 return info;
00098 }
00099 std::vector<double> getNorms() {
00100 return norms;
00101 }
00102 double getNumberOfIterations() {
00103 return iter;
00104 }
00105 double getNumberOfMaximalIterations() {
00106 return itermax;
00107 }
00108 void setNumberOfMaximalIterations(int itermax_) {
00109 itermax = itermax_;
00110 }
00111 double getTolerance() {
00112 return tol;
00113 }
00114 void setTolerance(double tol_) {
00115 tol = tol_;
00116 }
00117
00118
00119 fmatvec::Vec solve(const fmatvec::Vec &initialGuess);
00120
00121 private:
00125 Function1<fmatvec::Vec, fmatvec::Vec> *function;
00126
00130 double tol;
00131
00135 int iter;
00136
00140 double itermax;
00141
00145 std::vector<double> norms;
00146
00150 int info;
00151 };
00152
00158 class NewtonMethod {
00159 public:
00160
00161
00162
00163
00164
00165 NewtonMethod(Function1<double,double> *fct_, Function1<double,double> *jac_=0);
00166
00167
00168 int getNumberOfIterations() const { return iter; }
00169 int getInfo() const { return info; }
00170 void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
00171 void setMaximumDampingSteps(int kmax_) { kmax = kmax_; }
00172 void setTolerance(double tol_) { tol = tol_; }
00173
00174
00179 double solve(const double &x);
00180
00181 private:
00185 Function1<double,double> *fct;
00186
00190 Function1<double,double> *jac;
00191
00195 int itmax, iter, kmax, info;
00196
00200 double tol;
00201 };
00202
00208 class MultiDimNewtonMethod {
00209 public:
00210
00211
00212
00213
00214
00215 MultiDimNewtonMethod(Function1<fmatvec::Vec,fmatvec::Vec> *fct_, Function1<fmatvec::SqrMat,fmatvec::Vec> *jac_=0);
00216
00217
00218 int getNumberOfIterations() const { return iter; }
00219 int getNumberOfMaximalIterations() const { return itmax; }
00220 int getInfo() const { return info; }
00221 std::vector<double> getNorms() { return norms; }
00222 void setMaximumNumberOfIterations(int itmax_) { itmax = itmax_; }
00223 void setMaximumDampingSteps(int kmax_) { kmax = kmax_; }
00224 void setTolerance(double tol_) { tol = tol_; }
00225
00226
00231 fmatvec::Vec solve(const fmatvec::Vec &x);
00232
00233 private:
00237 Function1<fmatvec::Vec,fmatvec::Vec> *fct;
00238
00242 Function1<fmatvec::SqrMat,fmatvec::Vec> *jac;
00243
00247 int itmax, iter, kmax, info;
00248
00252 std::vector<double> norms;
00253
00257 double tol;
00258 };
00259
00260 }
00261
00262 #endif
00263