00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef O2SCL_MROOT_H
00024 #define O2SCL_MROOT_H
00025
00026 #include <o2scl/ovector_tlate.h>
00027 #include <o2scl/mm_funct.h>
00028 #include <o2scl/jacobian.h>
00029
00030 #ifndef DOXYGENP
00031 namespace o2scl {
00032 #endif
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 template<class param_t, class func_t, class vec_t=ovector_view,
00061 class jfunc_t=jac_funct<param_t,vec_t,omatrix_view> > class mroot {
00062
00063 public:
00064
00065 mroot() {
00066 ntrial=100;
00067 tolf=1.0e-8;
00068 verbose=0;
00069 tolx=1.0e-12;
00070 last_ntrial=0;
00071 }
00072
00073 virtual ~mroot() {}
00074
00075
00076 double tolf;
00077
00078
00079 double tolx;
00080
00081
00082 int verbose;
00083
00084
00085 int ntrial;
00086
00087
00088 int last_ntrial;
00089
00090
00091 virtual const char *type() { return "mroot"; }
00092
00093
00094 virtual int msolve(size_t n, vec_t &x, param_t &pa, func_t &func) {
00095 set_err_ret("mmroot::msolve() not implemented.",o2scl::gsl_eunimpl);
00096 }
00097
00098
00099
00100
00101
00102
00103
00104 virtual int msolve_de(size_t n, vec_t &x, param_t &pa, func_t &func,
00105 jfunc_t &dfunc) {
00106 return msolve(n,x,pa,func);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 template<class vec2_t, class vec3_t>
00124 int print_iter(size_t n, const vec2_t &x, const vec3_t &y,
00125 int iter, double value=0.0, double limit=0.0,
00126 std::string comment="")
00127 {
00128 if (verbose<=0) return o2scl::gsl_success;
00129
00130 char ch;
00131
00132 std::cout << comment << " Iteration: " << iter << std::endl;
00133 for(size_t i=0;i<n;i++) {
00134 std::cout.width(3);
00135 std::cout << i;
00136 if (x[i]>=0.0) {
00137 std::cout << " " << x[i];
00138 } else {
00139 std::cout << " " << x[i];
00140 }
00141 if (y[i]>=0.0) {
00142 std::cout << " " << y[i] << std::endl;
00143 } else {
00144 std::cout << " " << y[i] << std::endl;
00145 }
00146 }
00147 std::cout << "Val: " << value << " Lim: " << limit << std::endl;
00148 if (verbose>1) {
00149 std::cout << "Press a key and type enter to continue. ";
00150 std::cin >> ch;
00151 }
00152
00153 return o2scl::gsl_success;
00154
00155 }
00156
00157 };
00158
00159 #ifndef DOXYGENP
00160
00161 template<> int io_tlate<mroot<void *,mm_funct<void *> > >::input
00162 (cinput *co, in_file_format *ins, mroot<void *, mm_funct<void *> > *ro);
00163 template<> int io_tlate<mroot<void *,mm_funct<void *> > >::output
00164 (coutput *co, out_file_format *outs, mroot<void *, mm_funct<void *> > *ro);
00165 template<> const char *io_tlate<mroot<void *,mm_funct<void *> > >::type();
00166
00167 #endif
00168
00169 typedef io_tlate<mroot<void *,mm_funct<void *> > > mroot_io_type;
00170
00171 #ifndef DOXYGENP
00172 }
00173 #endif
00174
00175 #endif