Exemple #1
0
def test2():
    import matplotlib.pyplot as plt

    T = np.arange(0, 20.0, 0.01)
    sys = (G, K, sll.gain(3.7), sll.add, sll.fun_gen(A=3.0, omega=2), sll.add,
           sll.gain(1.0), sll.function(np.random.randn,
                                       1), sll.step(5.0), L, 1, 0)
    x0 = ([1.0, 0.6], [], [], [], [], [], [], [0.0, 0.0], [], [])

    # sys = (sll.sub,sll.int1,sll.fun_gen(A=1.0,omega=2*np.pi*2.0,bias=1.0),sll.time)
    # x0 = ([],[0.0],[],[],[])

    # sys = (G,K,x_ref,L,0,1)
    M = sl.MDL(sys, x0, "this")
    M.print_table()

    PW = sll.plot_window([0, 1], [9, 0], [9, 1], plot_separate=False)
    # PW2 = sll.plot_window([0], [5], [2], [0], plot_separate=False, active_draw=True)
    fig, ax = PW.return_axes()
    ax[1].set_xlabel("no time?")

    x0 = np.transpose(np.matrix(M.x0))
    T,X,Y = ode.rungekutta4ad(M.der, T, x0 , outcall=M.all_out, \
     adaptive=False, min_dt=5e-3, e_tol=1e-4, realtime=True, plotcalls=[PW.animate])

    PW.show()
    plt.plot(T)
    plt.show()

    print T[-1]
    print X[-1]
Exemple #2
0
def test7():

    T = np.arange(-0.0, 10.0, 0.01)

    sys1 = (G, K, [], L, 1, 0, sll.int1, 2)
    x01 = ([1.0, 0.6], [], [], [0.0, 0.0], [], [], [0.0])
    M1 = sl.MDL(sys1, x01, 'sys1')
    M1.print_table()

    sys2 = (G, K, [], L, 1, 0)
    x02 = ([0.0, 0.0], [], [], [0.0, 0.0], [], [], [])
    M2 = sl.MDL(sys2, x02, 'sys2')
    M2.print_table()

    x_in = np.matrix('8.0')

    sys = (sll.gain(5.2), M1, sll.sub, [], M2, 0)
    x0 = ([], M1.x0, [], [], M2.x0, [])

    M = sl.MDL(sys, x0, 'false algebraic loop')
    M.print_table()
    # M = sl.unpack_MDL(M)
    # M.print_table()

    PW = sll.plot_window([0, 2, 4], [0], [1, 0], plot_separate=True)
    fig, axes = PW.return_axes()
    axes[1].legend(['out', 'sys1-G'])

    x0 = np.transpose(np.matrix(M.x0))
    # y0 = M.all_out(T[0], x0, x_in)
    # print y0

    # print [ y0[i] for i in range(0,len(y0))]
    # dx0 = M.der(T[0], x0, x_in)
    # print dx0


    T,X,Y = ode.rungekutta4ad(M.der, x_in, T, x0 , outcall=M.all_out, \
     adaptive=False, realtime=False, plotcalls=[PW.animate], plottime=0.01)

    PW.show()

    print T[-1]
    print X[-1]
    print Y[-1].probe_s([0], [1, 0], [1, 1])
Exemple #3
0
def test0():
    sys = (sll.gain(3.4), [])
    x0 = ([], )

    G1 = sl.MDL(sys, x0, 'sys_gain1')

    M = sl.MDL((G1, sll.const(1.5)), ([], []), 'sys1')
    M = sl.unpack_MDL(M)
    sys[0].k = 1.0

    # x0 = np.transpose(np.matrix(M.x0))
    t = np.arange(0, 1, 0.01)

    T, X = ode.rungekutta4ad(M.der, t, x0)
    Y = [M.out(t, x) for t, x in zip(T, X)]
    print T[-1]
    print X[-1]
    print Y[-1]
Exemple #4
0
def test8():
    import matplotlib.pyplot as plt
    x_ref = [1.0]

    T = np.arange(0, 10.0, 0.01)
    sys = (G, K, [], L, 1, 0)
    x0 = ([1.0, 0.6], [], [], [0.0, 0.0], [], [], [])
    # sys = (G,K,[],L,0,1) # try this, it'll cause an error

    M = sl.MDL(sys, x0, "this")
    x0 = np.transpose(np.matrix(M.x0))

    T, X = ode.rungekutta4ad(M.der, x_ref, T, x0)
    Y = [M.out(t, x, x_ref).probe_s([0], [1]) for t, x in zip(T, X)]

    print T[-1]
    print X[-1]
    print Y[-1]
    plt.plot(T, [np.array(x)[:, 0] for x in X])
    plt.show()
Exemple #5
0
def test4():
    import matplotlib.pyplot as plt

    T = np.arange(0, 5.0, 0.01)
    d_in = np.matrix([1.0])

    sys_1 = (G, K, sll.gain(3.7), [], L, 1, 0)
    x0_1 = ([1.0, 0.6], [], [], [], [0.0, 0.0])

    M1 = sl.MDL(sys_1, x0_1, "Model KGL1")
    # M1.print_table()

    sys_2 = (G, K, M1, [], L, 1, 0)
    x0_2 = ([1.5, 0.6], [], M1.x0, [], [0.0, 0.0], [], [])

    M2 = sl.MDL(sys_2, x0_2, "Model KGL21")
    # M2.print_table()

    sys_12 = (M1, M2, D, ES, [])
    x0_12 = (M1.x0, M2.x0, [0.0, 0.0], [], [], [])

    M = sl.MDL(sys_12, x0_12, "Model KGL1+KGL21-G")
    assert sl.verify(M)
    M.print_table()

    # M = sl.unpack_MDL(M)
    # assert sl.verify(M)
    # M.print_table()

    # M.out(0.0,x0,d_in)
    x0 = np.transpose(np.matrix(M.x0))
    T, X = ode.rungekutta4ad(M.der, d_in, T, x0)
    Y = [M.out(t, x, d_in) for t, x in zip(T, X)]

    print T[-1]
    print X[-1]
    print Y[-1]
    print Y[-1].probe_s([0], [2], [3])
    plt.plot(T, [np.array(x)[:, 0] for x in X])
    plt.show()