Skip to main content

A minimal Python interface for computing inverse Laplace transforms using Talbot’s method — designed as a clean and practical wrapper around sympy & mpmath

Project description

iLaplace

A Simple Interface for Powerful Math

iLaplace is a lightweight Python wrapper around advanced symbolic and numerical math tools (sympy, numpy & mpmath) that provides a clean and intuitive interface for computing inverse Laplace transforms using Talbot's method.

I created this library to simplify the process of using the inverse Laplace transform, aiming to provide a MATLAB-like experience within Python. This means the output of my code in Python will be compared against a sample calculation in MathWorks MATLAB.


Why This Library?

If you've ever tried to compute inverse Laplace transforms numerically in Python, you've probably noticed:

  • mpmath.invertlaplace() is powerful but raw and low-level.
  • sympy gives symbolic transforms, but not numerical answers.
  • Combining them can be verbose and repetitive.

In short: You focus on the math, we handle the machinery.


MATLAB vs. Python Comparison

Here is a sample calculation in MATLAB and its equivalent in Python using this library.

MATLAB Example

syms s t
X = (s+3)/((s+1)^2 + (s^2+9));
V = vpa(ilaplace(X, s, t));
t0   = 5.2643;
Volt = double(subs(V, t, t0));
disp(Volt)

The output in MATLAB is -0.020100091042301.

Python Equivalent with iLaplace

import iLaplace as il
import sympy as sp
t, s = sp.symbols('t s')
X = (s+3)/((s+1)**2 + (s**2+9))
t0 = 5.2643
Answer = il.inverse_laplace(X, t0)
print(Answer)

And the output is -0.020100091042300372.

##See more examples:

2nd Example:

import iLaplace as il
import sympy as sp
import numpy as np
s, t = sp.symbols('s t')
t0 = 5.2643
X = (3) / ((s**2) +  (3**2))
Answer = il.inverse_laplace(X, t0)
print(Answer)

the output is -0.08483425637752962.

MATLAB Example

syms s t
format long
X= 3 / (s^2 + 3^2);
V = vpa(ilaplace(X, s, t));
t0   = 5.2643;
Volt = double(subs(V, t, t0));
disp(Volt)

and The output in MATLAB is -0.084834643101466.

3rd Example:

import iLaplace as il
import sympy as sp
t, s = sp.symbols('t s')
t0 = 5.2643
X = ((s + 3) / ((s + 3)**2 + 25)
              + 1 / (s + 2)**3
              + sp.log((s + 10) / s))
Answer = il.inverse_laplace(X, t0)
print(Answer)

the output is 0.19032962256026703.

MATLAB Example

syms s t
X = (s + 3) / ((s + 3)^2 + 25) ...
    + 1 / (s + 2)^3 ...
    + log((s + 10) / s);  
V = vpa(ilaplace(X, s, t));
t0   = 5.2643;
Volt = double(subs(V, t, t0));
disp(Volt)

and The output in MATLAB is 0.190329629407706.

4th Example:

import iLaplace as il
import sympy as sp
t, s = sp.symbols('t s')
t0 = 5.2643
#######################################
X1 = ((s + 3) / ((s + 3)**2 + 25)
              + 1 / (s + 2)**3
              + sp.log((s + 10) / s))
X2 = (s+3)/((s+1)**2 + (s**2+9))
X3 = (3) / ((s**2) +  (3**2))
#######################################
X= X1 + X2 + X3
Answer = il.inverse_laplace(X, t0)
print(Answer)

the output is 0.08539527514043704.

MATLAB Example

syms s t
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X1 = (s + 3) / ((s + 3)^2 + 25) ...
    + 1 / (s + 2)^3 ...
    + log((s + 10) / s);
X2 = (s+3)/((s+1)^2 + (s^2+9));
X3 = 3 / (s^2 + 3^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X = X1 + X2 + X3;
V = vpa(ilaplace(X, s, t));
t0   = 5.2643;
Volt = double(subs(V, t, t0));
disp(Volt)

and The output in MATLAB is 0.085394895263940.

License and Attributions

This project is licensed under the MIT License.

It internally utilizes components from the following libraries: mpmath & sympy.

All third-party libraries retain their original licenses and attributions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ilaplace-2.1.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iLaplace-2.1.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file ilaplace-2.1.3.tar.gz.

File metadata

  • Download URL: ilaplace-2.1.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for ilaplace-2.1.3.tar.gz
Algorithm Hash digest
SHA256 dacad7c5b90f08a7b06f665ebeeab1990d134110041e0fb178bd13dcb9ae8635
MD5 4ae999e88e831fd28178a5631bade349
BLAKE2b-256 bad8acaa65c1d5ca5e35c77cc4ff4c0af7b9a23618bfcdc35518a17ceef655a2

See more details on using hashes here.

File details

Details for the file iLaplace-2.1.3-py3-none-any.whl.

File metadata

  • Download URL: iLaplace-2.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for iLaplace-2.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 afb444ca22c97573bad1e52dba7d9b88725aa0423eb4d50e46c47b058ff95b4a
MD5 b3ffe7c4001308fed4dc57bf0fdd883e
BLAKE2b-256 c4355080b1917724a36136daf96370184ee5d396610c144de946164ad854b91b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page