Example #1
0
def main():
    """Solve Lyapunov Equation SO1 System."""

    # read data
    m = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/M_301.mtx").tocsr()
    d = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/D_301.mtx").tocsr()
    k = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/K_301.mtx").tocsr()

    # generate rhs
    b = np.ones((2 * m.shape[0], 1), dtype=np.double)

    # bounds for shift parameters
    lowerbound = 1e-8
    upperbound = 1e+8

    # create options instance
    opt = Options()
    opt.adi.output = 0
    opt.adi.res2_tol = 1e-7
    opt.type = MESS_OP_NONE

    # create equation
    eqn = EquationGLyapSO1(opt, m, d, k, b, lowerbound, upperbound)

    # solve equation
    z, status = lradi(eqn, opt)

    # get residual
    res2 = status.res2_norm
    res2_0 = status.res2_0
    it = status.it
    print("it = %d \t rel_res2 = %e\t res2 = %e \n" % (it, res2 / res2_0, res2))
    print("Size of Low Rank Solution Factor Z: %d x %d \n"%(z.shape))
    print(status)
Example #2
0
def main():
    """Demonstrate Callback functionality"""

    # read data
    a = mmread('@CMAKE_SOURCE_DIR@/tests/data/Rail/A.mtx')
    b = mmread('@CMAKE_SOURCE_DIR@/tests/data/Rail/B.mtx')
    c = mmread('@CMAKE_SOURCE_DIR@/tests/data/Rail/C.mtx')
    e = mmread('@CMAKE_SOURCE_DIR@/tests/data/Rail/E.mtx')

    # create options
    opt = Options()
    opt.nm.output = 0
    opt.adi.output = 0

    # create instance of MyEquation and solve
    opt.type = MESS_OP_NONE
    eqn1 = MyEquation(opt, a, e, b, c)
    z1, stat1 = lrnm(eqn1, opt)

    # create instance of MyEquation and solve
    opt.type = MESS_OP_TRANSPOSE
    eqn2 = MyEquation(opt, a, e, b, c)
    z2, stat2 = lrnm(eqn2, opt)

    # print information and compute residual again to make sure that we have everything correct
    print("\n")
    print("MyEquation: eqn1")
    print("Size of Low Rank Solution Factor Z1: %d x %d \n" % (z1.shape))
    print(stat1.lrnm_stat())
    nrmr1, nrmrhs1, relnrm1 = res2_ric(a, e, b, c, z1, MESS_OP_NONE)
    print("check for eqn1:\t rel_res2=%e\t res2=%e\t nrmrhs=%e\n" %
          (relnrm1, nrmr1, nrmrhs1))

    print("\n")
    print(
        "--------------------------------------------------------------------------------------"
    )
    print("\n")

    # print information and compute residual again to make sure that we have everything correct
    print("MyEquation: eqn2")
    print("Size of Low Rank Solution Factor Z2: %d x %d \n" % (z2.shape))
    print(stat2.lrnm_stat())
    nrmr2, nrmrhs2, relnrm2 = res2_ric(a, e, b, c, z2, MESS_OP_TRANSPOSE)
    print("check for eqn1:\t rel_res2=%e\t res2=%e\t nrmrhs=%e\n" %
          (relnrm2, nrmr2, nrmrhs2))
Example #3
0
def main():
    """Solve Riccati Equation SO1 System equation."""

    # read data
    m = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/M_301.mtx").tocsr()
    d = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/D_301.mtx").tocsr()
    k = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/K_301.mtx").tocsr()

    # generate rhs
    b = np.ones((2 * m.shape[0], 1), dtype=np.double)
    c = np.ones((1, m.shape[0]), dtype=np.double)

    # bounds for shift parameters
    lowerbound = 1e-8
    upperbound = 1e+8

    # create options instance
    opt = Options()
    opt.adi.output = 0
    opt.nm.output = 0
    opt.nm.res2_tol = 1e-6
    opt.adi.res2_tol = 1e-10
    opt.adi.maxit = 1000
    opt.type = MESS_OP_NONE
    opt.adi.shifts.paratype = MESS_LRCFADI_PARA_MINMAX

    # create equation
    eqn = EquationGRiccatiSO1(opt, m, d, k, b, c, lowerbound, upperbound)

    # solve equation
    z, status = lrnm(eqn, opt)

    # get residual
    res2 = status.res2_norm
    res2_0 = status.res2_0
    it = status.it
    print("it = %d \t rel_res2 = %e\t res2 = %e \n" %
          (it, res2 / res2_0, res2))
    print("Size of Low Rank Solution Factor Z: %d x %d \n" % (z.shape))
    print(status.lrnm_stat())