30#include "gsl/gsl_sf_gamma.h"
31#include "gsl/gsl_sf_pow_int.h"
37std::vector< std::vector< std::vector<int> > >
Tanh::_tdi;
39Tanh::Tanh(
double x0,
double lambda,
int max_index) : _x0(x0), _lambda(lambda) {
46 return new Tanh(*
this);
53 double lam_n = gsl_sf_pow_int(
_lambda, n);
55 for (
size_t i = 0; i <
_tdi[n].size(); i++)
56 t += 1./lam_n*
static_cast<double>(
_tdi[n][i][0])
57 *gsl_sf_pow_int(tanh_x,
_tdi[n][i][1]);
64 double lam_n = gsl_sf_pow_int(
_lambda, n);
66 for (
size_t i = 0; i <
_tdi[n].size(); i++)
67 t += 1./lam_n*
static_cast<double>(
_tdi[n][i][0])
68 *gsl_sf_pow_int(tanh_x,
_tdi[n][i][1]);
83 if (
_tdi.size() == 0) {
84 _tdi.push_back(std::vector< std::vector<int> >(1, std::vector<int>(2)));
88 for (
size_t i =
_tdi.size(); i < n+1; ++i) {
89 _tdi.push_back(std::vector< std::vector<int> >());
90 for (
size_t j = 0; j <
_tdi[i-1].size(); ++j) {
91 int value =
_tdi[i-1][j][1];
93 std::vector<int> new_vec(
_tdi[i-1][j]);
96 _tdi[i].push_back(new_vec);
97 std::vector<int> new_vec2(
_tdi[i-1][j]);
98 new_vec2[0] *= -value;
100 _tdi[i].push_back(new_vec2);
120 out <<
"Tanh model with centre length: " <<
_x0
std::vector< std::vector< int > > CompactVector(std::vector< std::vector< int > > vec)
Calculate the Tanh function (e.g.
virtual void setMaximumDerivative(size_t n)
Set the maximum derivative prior to tracking.
static void setTanhDiffIndices(size_t n)
Set the value of tanh differential indices to nth order differentials.
double function(double x, int n) const
Double Tanh is given by .
double getNegTanh(double x, int n) const
Returns the value of tanh((x-x0)/lambda) or its derivative.
std::ostream & print(std::ostream &out) const
Prints a human readable string to out.
static std::vector< std::vector< int > > getTanhDiffIndices(size_t n)
Get all the tanh differential indices .
void rescale(double scaleFactor)
Rescale the end field by a factor x0.
~Tanh()
Destructor (no mallocs so does nothing)
Tanh * clone() const
Inherited copy constructor.
static std::vector< std::vector< std::vector< int > > > _tdi
_tdi indexes powers of tanh in d^n tanh/dx^n as sum of powers of tanh
Tanh()
Default constructor (initialises x0 and lambda to 0)
double getTanh(double x, int n) const
Returns the value of tanh((x+x0)/lambda) or its derivative.