コード例 #1
0
def test_SetMatrixDim5_Random():
    Ntests = 1  # 2
    dim = 5
    X = []
    dX = []
    for i in range(dim):
        xi = Variable("x%d" % i)
        X.append(xi)
        dX.append(xi.dt)
    X = np.array(X)
    dX = np.array(dX)
    for i in range(Ntests):
        M = randomSymmetricMatrix(dim)
        V = np.random.rand(dim, dim)
        K = randomSymmetricMatrix(dim)
        A = np.random.rand(dim)
        B = np.random.rand(dim)
        C = np.random.rand()
        totalenergy = C
        totalenergy += np.dot(dX, np.dot(M, dX)) / 2
        totalenergy += np.dot(dX, np.dot(V, X))
        totalenergy += np.dot(X, np.dot(K, X)) / 2
        totalenergy += np.dot(A, dX)
        totalenergy += np.dot(B, X)
        E = Energy.frommatrix(X=X, M=M, V=V, K=K, A=A, B=B, C=C)
        assert E == totalenergy
コード例 #2
0
def test_SetMatrixDim2_Random():
    Ntests = 1  # 2
    x = Variable("x")
    y = Variable("y")
    X = np.array([x, y])
    dX = np.array([x.dt, y.dt])
    for i in range(Ntests):
        M = randomSymmetricMatrix(2)
        V = np.random.rand(2, 2)
        K = randomSymmetricMatrix(2)
        A = np.random.rand(2)
        B = np.random.rand(2)
        C = np.random.rand()
        totalenergy = C
        totalenergy += np.dot(dX, np.dot(M, dX)) / 2
        totalenergy += np.dot(dX, np.dot(V, X))
        totalenergy += np.dot(X, np.dot(K, X)) / 2
        totalenergy += np.dot(A, dX)
        totalenergy += np.dot(B, X)
        E = Energy.frommatrix(X=X, M=M, V=V, K=K, A=A, B=B, C=C)
        assert E == totalenergy
コード例 #3
0
def test_SetMatrixDim2_Standard():
    x = Variable("x")
    y = Variable("y")
    dx = x.dt
    dy = y.dt
    X = (x, y)

    M = np.array([[14, 2], [2, 12]])
    V = np.array([[4, 6], [3, 5]])
    K = np.array([[-6, -3], [-3, -10]])

    A = np.array([1, -7])
    B = np.array([-5, 9])
    C = 80

    ener = 7*(dx**2) + 2*dx*dy + 6*(dy**2) + \
           4*dx*x + 6*dx*y + 3*dy*x + 5*dy*y + \
           (-3)*x**2 + (-3)*x*y + (-5)*y**2 + \
           1*dx + (-7)*dy + (-5)*x + 9*y + 80
    E = Energy.frommatrix(X=X, M=M, V=V, K=K, A=A, B=B, C=C)
    ener = Energy(ener)
    assert E == ener