MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / ilt

Function ilt

SLiCAP/SLiCAPmath.py:1929–2007  ·  view source on GitHub ↗

Returns the Inverse Laplace Transform f(t) of an expression F(s) for t > 0. :param expr: Function of the Laplace variable F(s). :type expr: Sympy expression, integer, float, or str. :param s: Laplace variable :type s: sympy.Symbol :param t: time variable :type t: symp

(expr, s, t, integrate=False)

Source from the content-addressed store, hash-verified

1927 return expr
1928
1929def ilt(expr, s, t, integrate=False):
1930 """
1931 Returns the Inverse Laplace Transform f(t) of an expression F(s) for t > 0.
1932
1933 :param expr: Function of the Laplace variable F(s).
1934 :type expr: Sympy expression, integer, float, or str.
1935
1936 :param s: Laplace variable
1937 :type s: sympy.Symbol
1938
1939 :param t: time variable
1940 :type t: sympy.Symbol
1941
1942 :param integrate: True multiplies expr with 1/s, defaults to False
1943 :type integrate: Bool
1944
1945 :return: Inverse Laplace Transform f(t)
1946 :rtype: sympy.Expr
1947 """
1948 inv_laplace = None
1949 if type(expr) == float or type(expr) == int:
1950 expr = sp.N(expr)
1951 elif type(expr) == str:
1952 expr = sp.sympify(expr)
1953 variables = sp.N(expr).atoms(sp.Symbol)
1954 if len(variables) == 0 or s not in variables:
1955 inv_laplace = sp.DiracDelta(t)*expr
1956 elif len(variables) == 1 and s in variables:
1957 num, den = expr.as_numer_denom()
1958 if num.is_polynomial() and den.is_polynomial():
1959 polyDen = sp.Poly(den, s)
1960 gainD = sp.Poly.LC(polyDen)
1961 denCoeffs = polyDen.all_coeffs()
1962 denCoeffs = [sp.N(coeff/gainD) for coeff in denCoeffs]
1963 if integrate:
1964 denCoeffs.append(0)
1965 den = Polynomial(np.array(denCoeffs[::-1], dtype=float))
1966 rts = den.roots()
1967 rootDict = {}
1968 for rt in rts:
1969 if rt not in rootDict.keys():
1970 rootDict[rt] = 1
1971 else:
1972 rootDict[rt] += 1
1973 rts = rootDict.keys()
1974 polyNum = sp.Poly(num, s)
1975 numCoeffs = polyNum.all_coeffs()
1976 numCoeffs = [sp.N(numCoeff/gainD) for numCoeff in numCoeffs]
1977 num = sp.Poly(numCoeffs, s)
1978 inv_laplace = 0
1979 for root in rts:
1980 # get root multiplicity
1981 n = rootDict[root]
1982 # build the function
1983 fs = num.as_expr()*sp.exp(s*t)
1984 for rt in rts:
1985 if rt != root:
1986 fs /= (s-rt)**rootDict[rt]

Callers 4

_doImpulseFunction · 0.90
_doStepFunction · 0.90
_doTimeFunction · 0.90
_doTimeSolveFunction · 0.90

Calls 3

assumeRealParamsFunction · 0.85
clearAssumptionsFunction · 0.85
_symiltFunction · 0.85

Tested by

no test coverage detected