[Python] When I use ss2tf on the python control package I get extra terms in the numerator

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, with the control package in python. I write the different state space matrices, and convert that system to transfer functions (ss2tf function in the python control system library).

    I seem to be getting some weird values one some states. In the example below I get the response from input 1 to output 2 (H[1,2])to be

    0.2991 s + 14.96
    --------------------
    s^2 + 50 s + 0.02381


    When I manually do the calculations I get

    0.2991
    --------------------
    s + 0.000476190476


    It seems as the expressions are quite similar if I do some rounding and factor out the first expression. But I don't understand why I get higher order transfer functions when I do ss2tf.

    See the code above. Appreciate the answers!

    #Parameters defining the system
    V = 20000 #[m^3 volume in tank]
    K_qo = 20000/(35*60)
    C = np.pi * 20.25**2
    O2Sea = 7 #g/m^3


    K = 104.2*10**3/(60**2)
    K1 = 20000/((60**2) * 130)
    K2 = 7 * K1
    T=0.02

    s= sy.symbols('s')

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

    b0 = K1/C
    b1 = K2
    b2 = K/T


    A = np.array([[-a0, 0, 0,0,0],
    [0, -a1, 1,1,1],
    [0, 0, -a2 ,0, 0],
    [0, 0, 0, -a2, 0],
    [0, 0, 0, 0, -a2]
    ])

    B = np.array([[b0, b0, b0, 0, 0,0,0],
    [b1, b1, b1, 0, 0, 0, -1],
    [0, 0, 0, b2, 0, 0, 0],
    [0, 0, 0, 0, b2, 0, 0],
    [0, 0, 0, 0, 0, b2, 0]
    ])

    C = np.array([[0,0, 0,0,0],
    [0,1, 0,0,0],
    [0, 0, 0,0,0],
    ])

    D = 0



    ssmodel = ct.ss(A, B, C, D)
    print(ssmodel)

    H = ct.ss2tf(ssmodel)

    print(H[1,2])

    Continue reading...

Compartilhe esta Página