forked from codehouseindia/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInverse_laplace_transform.py
More file actions
36 lines (28 loc) · 1.11 KB
/
Inverse_laplace_transform.py
File metadata and controls
36 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sympy.polys.partfrac
from sympy.integrals.transforms import inverse_laplace_transform
from sympy.plotting import plot, plot3d
def partialFrac(f):
""" Function to return the partial fraction decomposition
of the equation in frequency domain(s)
"""
return sympy.polys.partfrac.apart(f)
def plot_graph(initial,final):
""" Function to Plot the original equation vs s(frequency)
and in time domain ater applying ILT in 2-D and 3-D.
"""
p1 = plot(initial)
p2 = plot(final)
plot3d(initial,final, (s, 0, 12), (t, 0,12))
return "Plots of Original equation in Frequency Domain and in Time Domain "
def invLaplace(f=(3*s + 2)/(s**2 -(3*s) +2)):
"""main function to call that will output the partial frac
as well as the final inverse laplace transform
"""
part = partialFrac(f)
print("Partial Fraction Decomposition: ",part)
ans = sympy.inverse_laplace_transform(part,s,t)
print("Inverse Laplace Transform is: ",ans)
return plot_graph(f,ans)
Eq = input("Enter a Equation:")
s,t = sympy.symbols('s t',positive=True)
invLaplace(eval(Eq))