def __call__(self,t): with mp.extradps(self.prec): t = mpf(t) if t == 0: print "ERROR: Inverse transform can not be calculated for t=0" return ("Error"); N = 2*self.N # Initiate the stepsize (mit aktueller Präsision) h = 2*pi/N # The for loop is evaluating the Laplace inversion at each point theta i # which is based on the trapezoidal rule ans = 0.0 for k in range(self.N): theta = -pi + (k+0.5)*h z = self.shift + N/t*(Talbot.c1*theta/tan(Talbot.c2*theta) - Talbot.c3 + Talbot.c4*theta) dz = N/t * (-Talbot.c1*Talbot.c2*theta/sin(Talbot.c2*theta)**2 + Talbot.c1/tan(Talbot.c2*theta)+Talbot.c4) v1 = exp(z*t)*dz prec = floor(max(log10(abs(v1)),0)) with mp.extradps(prec): value = self.F(z) ans += v1*value return ((h/pi)*ans).imag
def dTk(x): with mp.extradps(extradps): x = clip(x, -1.0, 1.0) if mp.almosteq(x, mp.one): return pos if mp.almosteq(x, -mp.one): return neg moredps = max( 0, int(-math.log10( min(abs(x - mp.one), abs(x + mp.one))) / 2)) moredps = min(moredps, 100) with mp.extradps(moredps): t = mp.acos(x) return k * mp.sin(k * t) / mp.sin(t)
def ddTk(x): with mp.extradps(extradps): x = clip(x, -1.0, 1.0) if mp.almosteq(x, mp.one): return pos if mp.almosteq(x, -mp.one): return neg moredps = max( 0, int(-math.log10( min(abs(x - mp.one), abs(x + mp.one))) * 1.5) + 2) moredps = min(moredps, 100) with mp.extradps(moredps): t = mp.acos(x) s = mp.sin(t) return -k**2 * mp.cos(k * t) / s**2 + k * mp.cos( t) * mp.sin(k * t) / s**3
def G(self,s): # Laplace-Transform zz = 2*self.v + 2 + s mu = sqrt(self.v**2+2*zz) a = mu/2 - self.v/2 - 1 b = mu/2 + self.v/2 + 2 v1 = (2*self.alp)**(-a)*gamma(b)/gamma(mu+1)/(zz*(zz - 2*(1 + self.v))) prec = floor(max(log10(abs(v1)),mp.dps))+self.prec # additional precision needed for computation of hyp1f1 with mp.extradps(prec): value = hyp1f1(a,mu + 1,self.beta)*v1 return value
def init(self, use_mp=False): r"""This should be called during the solving process to prepare the internal state. The main purpose of splitting initialization from class construction is that during construction (which is done by the user of the `NDSolver` and not controlled by the `NDSolver` itself), we might not have the desired state of the mpmath arbitrary precision library context. Once the solver is entered, we know the desired `dps` (decimal places) and that is when all the computation should take place. """ self._use_mp = use_mp self.ctx = mp if use_mp else fp self._pts_internal = self._collocation_points() self._pts = transform_domains(self.pts_internal, self.internal_domain(), self._domain, use_mp=use_mp) fl = mp.mpf if use_mp else float with mp.extradps(15 if use_mp else 0): a, b = lmap(fl, self.internal_domain()) c, d = lmap(fl, self.domain) self._scl = (b - a) / (d - c)