Search code examples
pythontransformsympyinverse

SymPy - Generates huge equation while inverse laplace transform


When I do a really simple inverse laplace transform with Sympy, I got a huge equation back.

For example:

from sympy import *
s = symbols ('s')
t = symbols ('t', positive=True) # Just to remove the Heaviside(t) equations
k, m = symbols ('k m', const=True) 
A = Matrix([[0, 1], [-k/m, 0]])
I = eye(2) # Diagonalmatrix 
Fi = inverse_laplace_transform((s*I-A).inv(), s,  t)
print(pretty(simplify(Fi)))

Now a get an enormous huge equation from Fi. Why? Is something wrong with inverse_laplace_transform() function from Sympy?


Solution

  • Inverse lapace transform is used to turn transfer functiuons into discrete form instead of time continuous.

    Instead of using inverse laplace transform, we can use this code instead, where h is the sample time. Image that we have a transfer function G(s), and you want to find the discrete equivalent model of G(s). Find the state space model of G(s) and then run this Octave/MATLAB code:

    % Compute sizes
    a1 = size(A,2) + size(B,2) - size(A,1);
    b1 = size(A,2);
    a2 = size(A,2) + size(B,2) - size(B,1);
    b2 = size(B,2);
    % Compute square matrix
    M = [A B; zeros(a1, b1)  zeros(a2, b2)];
    M = expm(M*h);
     % Find the discrete matrecies
    Ad = M(1:size(A,1), 1:size(A,2));
    Bd = M(1:size(B,1), (size(A,2) + 1):(size(A,2) + size(B,2)));
    

    Code source: https://github.com/DanielMartensson/Matavecontrol/blob/master/sourcecode/c2d.m