[Python] Matrix inverse in sympy

Discussão em 'Python' iniciado por Stack, Junho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm doing some prework for a control design of a system, and have started using SymPy. In my previous job I used MATLAB.

    In my system I have a matrix A, with these parameters:

    s= symbols('s')

    V = 20000 #[m^3 volume in tank]
    K_qo = 20000/(35*60)
    C = np.pi * 20.25**2

    a0 = K_qo/(0.06*C)
    a1 = K_qo/V
    T = 0.02

    A = Matrix([[-a0, 0, 0,0,0],
    [0, -a1, 1,1,1],
    [0, 0, -1/T ,0, 0],
    [0, 0, 0, -1/T, 0],
    [0, 0, 0, 0, -1/T]
    ])


    I want to calculate the state transition matrix $ \phi $

    To find this matrix I have to do this matrix manipulation: $ \phi = [sI-A]^{-1} $

    When i use the method='LA' i get the expected expression (second order). But if I use other methods, or the default method I get a higher order expression (fifth order) when my coefficient has a lot of decimals (I think). ie.:

    G=C*((s*eye(5)-A).inv(method='LU'))*B gives my expected result

    but G=C*((s*eye(5)-A).inv())*B

    gives a total different answer. Could any of you help me understand why this is happening? I want to try to avoid this in the future. This system was pretty simple, so I could kind of tell something was off. But in larger more complex systems I would not necessarily catch this.

    Continue reading...

Compartilhe esta Página