Last active
November 30, 2018 17:37
-
-
Save AndrewWalker/5583653 to your computer and use it in GitHub Desktop.
Numerical Inverse of the Laplace Transform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on "Approximate Inversion of the Laplace Transform" by Cheng and Sidauruk, | |
# in the Mathematica Journal, vol 4, issue 2, 1994 | |
import scipy.misc | |
fact = scipy.misc.factorial | |
def csteh(n, i): | |
acc = 0.0 | |
for k in xrange(int(np.floor((i+1)/2.0)), int(min(i, n/2.0))+1): | |
num = k**(n/2.0) * fact(2 * k) | |
den = fact(i - k) * fact(k -1) * fact(k) * fact(2*k - i) * fact(n/2.0 - k) | |
acc += (num /den) | |
expo = i+n/2.0 | |
term = np.power(-1+0.0j,expo) | |
res = term * acc | |
return res.real | |
def nlinvsteh(F, t, n = 6): | |
acc = 0.0 | |
lton2 = numpy.log(2) / t | |
for i in xrange(1, n+1): | |
a = csteh(n, i) | |
b = F(i * lton2) | |
acc += (a * b) | |
return lton2 * acc | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment