def pade9_i(self, h): U, V = self.pade9() p = ( 335221286400.0, 8821612800.0, 11762150400.0, 302702400.0, 90810720.0, 2162160.0, 205920.0, 3960.0, 110.0, 1.0, ) q = ( 335221286400.0, -158789030400.0, 35286451200.0, -4843238400.0, 454053600.0, -30270240.0, 1441440.0, -47520.0, 990.0, -10.0, ) P = h * ( mf._smart_matrix_product( self.A, p[9] * self.A8 + p[7] * self.A6 + p[5] * self.A4 + p[3] * self.A2 + p[1] * self.ident, structure=self.structure, ) + p[8] * self.A8 + p[6] * self.A6 + p[4] * self.A4 + p[2] * self.A2 + p[0] * self.ident ) Q = ( mf._smart_matrix_product( self.A, q[9] * self.A8 + q[7] * self.A6 + q[5] * self.A4 + q[3] * self.A2 + q[1] * self.ident, structure=self.structure, ) + q[8] * self.A8 + q[6] * self.A6 + q[4] * self.A4 + q[2] * self.A2 + q[0] * self.ident ) return U, V, P, Q
def pade7_i(self, h): U, V = self.pade7() p = (259459200.0, 8648640.0, 8648640.0, 277200.0, 55440.0, 1512.0, 72.0, 1.0) q = ( 259459200.0, -121080960.0, 25945920.0, -3326400.0, 277200.0, -15120.0, 504.0, -8.0, ) P = h * ( mf._smart_matrix_product( self.A, p[7] * self.A6 + p[5] * self.A4 + p[3] * self.A2 + p[1] * self.ident, structure=self.structure, ) + p[6] * self.A6 + p[4] * self.A4 + p[2] * self.A2 + p[0] * self.ident ) Q = ( mf._smart_matrix_product( self.A, q[7] * self.A6 + q[5] * self.A4 + q[3] * self.A2 + q[1] * self.ident, structure=self.structure, ) + q[6] * self.A6 + q[4] * self.A4 + q[2] * self.A2 + q[0] * self.ident ) return U, V, P, Q
def A5(self): if self._A5 is None: self._A5 = mf._smart_matrix_product( self.A, self.A4, structure=self.structure ) return self._A5
def _geti2(H, E, I, h, pade): """ A helper routine for expmint; computes I2. See :func:`expmint`. """ if pade <= 3: p = (450240.0, 104860.0, 15480.0, 1001.0) q = (900480.0, -390600.0, 66240.0, -4540.0) P = (h * h) * (p[3] * H.A3 + p[2] * H.A2 + p[1] * H.A + p[0] * H.ident) Q = q[3] * H.A3 + q[2] * H.A2 + q[1] * H.A + q[0] * H.ident return _solve_P_Q_2(P, Q, H.structure) if pade <= 5: p = ( 69363423360.0, 14569133040.0, 2595781440.0, 239983884.0, 14154000.0, 398959.0, ) q = ( 138726846720.0, -63346298400.0, 12740716800.0, -1425725280.0, 89937120.0, -2602278.0, ) P = (h * h) * ( mf._smart_matrix_product( H.A, p[5] * H.A4 + p[3] * H.A2 + p[1] * H.ident, structure=H.structure ) + p[4] * H.A4 + p[2] * H.A2 + p[0] * H.ident ) Q = ( mf._smart_matrix_product( H.A, q[5] * H.A4 + q[3] * H.A2 + q[1] * H.ident, structure=H.structure ) + q[4] * H.A4 + q[2] * H.A2 + q[0] * H.ident ) return _solve_P_Q_2(P, Q, H.structure) if pade <= 7: p = ( 41840477770291200.0, 8321436219096000.0, 1617627908856960.0, 159144893827920.0, 12344957190720.0, 614984330664.0, 19815037200.0, 312129649.0, ) q = ( 83680955540582400.0, -39144431255529600.0, 8411304436254720.0, -1081869058670400.0, 90503101180800.0, -4959510549840.0, 166265789760.0, -2658297528.0, ) P = (h * h) * ( mf._smart_matrix_product( H.A, p[7] * H.A6 + p[5] * H.A4 + p[3] * H.A2 + p[1] * H.ident, structure=H.structure, ) + p[6] * H.A6 + p[4] * H.A4 + p[2] * H.A2 + p[0] * H.ident ) Q = ( mf._smart_matrix_product( H.A, q[7] * H.A6 + q[5] * H.A4 + q[3] * H.A2 + q[1] * H.ident, structure=H.structure, ) + q[6] * H.A6 + q[4] * H.A4 + q[2] * H.A2 + q[0] * H.ident ) return _solve_P_Q_2(P, Q, H.structure) if pade <= 9: p = ( 69491589579005577984000.0, 13362425784392593708800.0, 2733673676598876211200.0, 274218651095712523200.0, 24016200124299102720.0, 1393079626219366800.0, 63177322465033920.0, 1972643393629480.0, 40190548856040.0, 403978495031.0, ) q = ( 138983179158011155968000.0, -65930601203222249894400.0, 14675286699176463360000.0, -2017982140321398451200.0, 189583633133409715200.0, -12669377873982429600.0, 604988181888330240.0, -20009929231749600.0, 418494695659920.0, -4247085597370.0, ) P = (h * h) * ( mf._smart_matrix_product( H.A, p[9] * H.A8 + p[7] * H.A6 + p[5] * H.A4 + p[3] * H.A2 + p[1] * H.ident, structure=H.structure, ) + p[8] * H.A8 + p[6] * H.A6 + p[4] * H.A4 + p[2] * H.A2 + p[0] * H.ident ) Q = ( mf._smart_matrix_product( H.A, q[9] * H.A8 + q[7] * H.A6 + q[5] * H.A4 + q[3] * H.A2 + q[1] * H.ident, structure=H.structure, ) + q[8] * H.A8 + q[6] * H.A6 + q[4] * H.A4 + q[2] * H.A2 + q[0] * H.ident ) return _solve_P_Q_2(P, Q, H.structure) # second, try direct solution: n = H.A.shape[0] with warnings.catch_warnings(): warnings.simplefilter("error", RuntimeWarning) try: lup = la.lu_factor(H.A) # decomp maybe worked ... check it: # I = A\(expm(A*h) - Ident) I_test = la.lu_solve(lup, h * (E - np.eye(n))) if np.allclose(I_test, I): # I2 = A\(expm(A*h)*h - A\(expm(A*h) - Ident)) return la.lu_solve(lup, h * (E * h - I_test)) except RuntimeWarning: pass # finally, use taylor series: msg = ( "Using power series expansion directly for `I2` (see" " `expmint`).\nRecommendation: use a finer time step." ) warnings.warn(msg, RuntimeWarning) I2 = np.eye(n) / 2 term = H.A j = 1.0 tol = 1e-15 maxloops = 200 while abs(term).max() > tol * abs(E).max() and j < maxloops: j += 1.0 I2 += term / (j + 1) term = term.dot(H.A) / j if j >= maxloops: raise RuntimeError( f"maximum loops ({maxloops}) exceeded for power series expansion" ) return (h * h) * I2
def A3(self): if self._A3 is None: self._A3 = mf._smart_matrix_product( self.A, self.A2, structure=self.structure ) return self._A3
def pade13_scaled_i(self, s, h): b = ( 64764752532480000.0, 32382376266240000.0, 7771770303897600.0, 1187353796428800.0, 129060195264000.0, 10559470521600.0, 670442572800.0, 33522128640.0, 1323241920.0, 40840800.0, 960960.0, 16380.0, 182.0, 1.0, ) B = self.A * 2 ** -s h = h * 2 ** -s B2 = self.A2 * 2 ** (-2 * s) B4 = self.A4 * 2 ** (-4 * s) B6 = self.A6 * 2 ** (-6 * s) U2 = mf._smart_matrix_product( B6, b[13] * B6 + b[11] * B4 + b[9] * B2, structure=self.structure ) U = mf._smart_matrix_product( B, (U2 + b[7] * B6 + b[5] * B4 + b[3] * B2 + b[1] * self.ident), structure=self.structure, ) V2 = mf._smart_matrix_product( B6, b[12] * B6 + b[10] * B4 + b[8] * B2, structure=self.structure ) V = V2 + b[6] * B6 + b[4] * B4 + b[2] * B2 + b[0] * self.ident p = ( 1748648318376960000.0, 32382376266240000.0, 64764752532480000.0, 1187353796428800.0, 593676898214400.0, 10559470521600.0, 2011327718400.0, 33522128640.0, 2793510720.0, 40840800.0, 1485120.0, 16380.0, 210.0, 1.0, ) q = ( 1748648318376960000.0, -841941782922240000.0, 194294257597440000.0, -28496491114291200.0, 2968384491072000.0, -232308351475200.0, 14079294028800.0, -670442572800.0, 25141596480.0, -735134400.0, 16336320.0, -262080.0, 2730.0, -14.0, ) _P2 = mf._smart_matrix_product( B6, p[13] * B6 + p[11] * B4 + p[9] * B2, structure=self.structure ) P2 = mf._smart_matrix_product( B, _P2 + p[7] * B6 + p[5] * B4 + p[3] * B2 + p[1] * self.ident, structure=self.structure, ) P1 = mf._smart_matrix_product( B6, p[12] * B6 + p[10] * B4 + p[8] * B2, structure=self.structure ) P = h * (P2 + P1 + p[6] * B6 + p[4] * B4 + p[2] * B2 + p[0] * self.ident) _Q2 = mf._smart_matrix_product( B6, q[13] * B6 + q[11] * B4 + q[9] * B2, structure=self.structure ) Q2 = mf._smart_matrix_product( B, _Q2 + q[7] * B6 + q[5] * B4 + q[3] * B2 + q[1] * self.ident, structure=self.structure, ) Q1 = mf._smart_matrix_product( B6, q[12] * B6 + q[10] * B4 + q[8] * B2, structure=self.structure ) Q = Q2 + Q1 + q[6] * B6 + q[4] * B4 + q[2] * B2 + q[0] * self.ident return U, V, P, Q