예제 #1
0
def test_t13(algorithm, const):
    def odefun(y, _, k):
        return 2 * y[1], 2 * ((y[0] - k[0] * np.pi ** 2 * np.cos(np.pi * y[2]) - np.cos(np.pi * y[2])) / k[0]), 2

    def odejac(y, _, k):
        df_dy = np.array([[0, 2, 0],
                          [2 / k[0], 0, (2 * (np.pi * np.sin(np.pi * y[2]) + k[0] * np.pi ** 3 * np.sin(np.pi * y[2])))
                           / k[0]], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0], yf[0] + 1, y0[2] + 1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm, num_arcs=2)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 0, -1], [0, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = np.cos(np.pi * sol.y[:, 2]) + np.exp(-(1 + sol.y[:, 2]) / np.sqrt(sol.k[0]))
    e2 = -np.pi * np.sin(np.pi * sol.y[:, 2]) - 1 / (
            np.sqrt(sol.k[0]) * np.exp((sol.y[:, 2] + 1) / np.sqrt(sol.k[0])))
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #2
0
def test_t1(algorithm, const):
    def odefun(y, _, k):
        return y[1], y[0] / k[0]

    def odejac(_, __, k):
        df_dy = np.array([[0, 1], [1 / k[0], 0]])
        df_dp = np.empty((2, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0] - 1, yf[0]

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 1], [0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = (np.exp(-sol.t / np.sqrt(sol.k)) - np.exp((sol.t - 2) / np.sqrt(sol.k))) / (
                1 - np.exp(-2.e0 / np.sqrt(sol.k)))
    e2 = (1. / (sol.k ** (1 / 2) * np.exp(sol.t / sol.k ** (1 / 2))) + np.exp(
            (sol.t - 2) / sol.k ** (1 / 2)) / sol.k ** (1 / 2)) / (1 / np.exp(2 / sol.k ** (1 / 2)) - 1)
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #3
0
def test_t10(algorithm, const):
    def odefun(y, _, k):
        return 2 * y[1], 2 * (-y[2] * y[1] / k[0]), 2

    def odejac(y, _, k):
        df_dy = np.array([[0, 2, 0], [0, 2 * (-y[2]) / k[0], 2 * (-y[1] / k[0])], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0], yf[0] - 2, y0[2] + 1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 0, -1], [2, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = 1 + erf(sol.y[:, 2] / np.sqrt(2 * sol.k[0])) / erf(1 / np.sqrt(2 * sol.k[0]))
    e2 = np.sqrt(2) / (np.sqrt(np.pi) * np.sqrt(sol.k[0]) * np.exp(sol.y[:, 2] ** 2 / (2 * sol.k[0])) * erf(
        np.sqrt(2) / (2 * np.sqrt(sol.k[0]))))
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #4
0
def test_t9(algorithm, const):
    def odefun(y, _, k):
        return 2 * y[1], 2 * (-(4 * y[2] * y[1] + 2 * y[0]) / (k[0] + y[2] ** 2)), 2

    def odejac(y, _, k):
        df_dy = np.array([[0, 2, 0],
                          [-4 / (y[2] ** 2 + k[0]), -(8 * y[2]) / (y[2] ** 2 + k[0]),
                           (4 * y[2] * (2 * y[0] + 4 * y[1] * y[2])) / (y[2] ** 2 + k[0]) ** 2
                           - (8 * y[1]) / (y[2] ** 2 + k[0])], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, k):
        return y0[0] - 1 / (1 + k[0]), yf[0] - 1 / (1 + k[0]), y0[2] + 1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm, num_arcs=2)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0., 1., 2)
    # noinspection PyTypeChecker
    solinit.y = np.array([[1. / (1. + const), 0., -1.], [1. / (1. + const), 1., 1.]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = 1 / (sol.k[0] + sol.y[:, 2] ** 2)
    e2 = -(2 * sol.y[:, 2]) / (sol.y[:, 2] ** 2 + sol.k[0]) ** 2
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #5
0
def test_t14(algorithm, const):
    def odefun(y, _, k):
        return 2 * y[1], 2 * ((y[0] - k[0] * np.pi ** 2 * np.cos(np.pi * y[2]) - np.cos(np.pi * y[2])) / k[0]), 2

    def odejac(y, _, k):
        df_dy = np.array([[0, 2, 0],
                          [2 / k[0], 0, (2 * (np.pi * np.sin(np.pi * y[2]) + k[0] * np.pi ** 3 * np.sin(np.pi * y[2])))
                           / k[0]], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0], yf[0], y0[2]+1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm, num_arcs=4)
    algo.set_derivative_jacobian(odejac)
    sol = Trajectory()
    sol.t = np.linspace(0, 1, 2)
    sol.y = np.array([[0, 0, -1], [0, 0, 1]])
    sol.k = np.array([const])
    # noinspection PyTypeChecker
    cc = np.linspace(const * 10, const, 10)
    for c in cc:
        sol = copy.deepcopy(sol)
        sol.k = np.array([c])
        sol = algo.solve(sol)['traj']

    e1 = np.cos(np.pi * sol.y[:, 2]) + np.exp(-(1 + sol.y[:, 2]) / np.sqrt(sol.k[0])) + np.exp(
        -(1 - sol.y[:, 2]) / np.sqrt(sol.k[0]))
    e2 = np.exp((sol.y[:, 2] - 1) / np.sqrt(sol.k[0])) / np.sqrt(sol.k[0]) - np.pi * np.sin(
        np.pi * sol.y[:, 2]) - 1 / (np.sqrt(sol.k[0]) * np.exp((sol.y[:, 2] + 1) / np.sqrt(sol.k[0])))
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #6
0
def test_t33(algorithm, const):
    def odefun(y, _, k):
        return y[1], (y[0]*y[3] - y[2]*y[1]) / k[0], y[3], y[4], y[5], (-y[2] * y[5] - y[0] * y[1]) / k[0]

    def odejac(y, _, k):
        df_dy = np.array(
            [[0, 1, 0, 0, 0, 0], [y[3] / k[0], -y[2] / k[0], -y[1] / k[0], y[0] / k[0], 0, 0], [0, 0, 0, 1, 0, 0],
             [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1], [-y[1] / k[0], -y[0] / k[0], -y[5] / k[0], 0, 0, -y[2] / k[0]]])
        df_dp = np.empty((6, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0] + 1, y0[2], y0[3], yf[0] - 1, yf[2], yf[3]

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm, num_arcs=12)
    algo.set_derivative_jacobian(odejac)
    sol = Trajectory()
    sol.t = np.linspace(0, 1, 2)
    sol.y = np.array([[-1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]])
    sol.k = np.array([const])
    # noinspection PyTypeChecker
    cc = np.linspace(const * 10, const, 10, dtype=np.float)
    for c in cc:
        sol = copy.deepcopy(sol)
        sol.k = np.array([c])
        sol = algo.solve(sol)['traj']

    assert sol.converged
예제 #7
0
def test_t4(algorithm, const):
    def odefun(y, _, k):
        return 2 * y[1], 2 * (((1 + k[0]) * y[0] - y[1]) / k[0]), 2

    def odejac(_, __, k):
        df_dy = np.array([[0, 2, 0], [2 * (1 + k[0]) / k[0], 2 * (-1) / k[0], 0], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, k):
        return y0[0] - 1 - np.exp(-2), yf[0] - 1 - np.exp(-2 * (1 + k[0]) / k[0]), y0[2] + 1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[-1, 0, -1], [-1, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = np.exp(sol.y[:, 2] - 1) + np.exp(-((1 + sol.k[0]) * (1 + sol.y[:, 2]) / sol.k[0]))
    e2 = np.exp(sol.y[:, 2] - 1) - (sol.k[0] + 1) / (
            sol.k[0] * np.exp((sol.y[:, 2] + 1) * (sol.k[0] + 1) / sol.k[0]))
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #8
0
def test_t3(algorithm, const):
    def odefun(y, _, k):
        return (2 * y[1], 2 * (-(2 + np.cos(np.pi * y[2])) * y[1] + y[0] - (1 + k[0] * np.pi * np.pi) * np.cos(
            np.pi * y[2]) - (2 + np.cos(np.pi * y[2])) * np.pi * np.sin(np.pi * y[2])) / k[0], 2)

    def odejac(y, _, k):
        df_dy = np.array([[0, 2, 0],
                          [2 / k[0], -(2 * np.cos(np.pi * y[2]) + 4)/k[0],
                           (2*np.pi**2 * np.sin(np.pi * y[2])**2 + 2 * np.pi*np.sin(np.pi*y[2])*(k[0]*np.pi**2 + 1)
                            - 2*np.pi**2*np.cos(np.pi*y[2])*(np.cos(np.pi*y[2]) + 2)
                            + 2*y[1]*np.pi*np.sin(np.pi*y[2]))/k[0]],
                          [0, 0, 0]], dtype=np.float)
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0] + 1, yf[0] + 1, y0[2] + 1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[-1, 0, -1], [-1, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = np.cos(np.pi * sol.y[:, 2])
    e2 = -np.pi * np.sin(np.pi * sol.y[:, 2])
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #9
0
def test_t31(algorithm, const):
    def odefun(y, _, k):
        return np.sin(y[1]), y[2], -y[3] / k[0], \
               ((y[0]-1) * np.cos(y[1]) - y[2] / np.cos(y[1]) - k[0] * y[3] * np.tan(y[1])) / k[0]

    def odejac(y, _, k):
        df_dy = np.array(
            [[0, np.cos(y[1]), 0, 0], [0, 0, 1, 0], [0, 0, 0, -1 / k[0]],
             [np.cos(y[1]) / k[0], -(np.sin(y[1]) * (y[0] - 1) + k[0] * y[3] * (np.tan(y[1]) ** 2 + 1)
                                     + (y[2] * np.sin(y[1])) / np.cos(y[1]) ** 2) / k[0], -1 / (k[0] * np.cos(y[1])),
              -np.tan(y[1])]])
        df_dp = np.empty((4, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0], y0[2], yf[0], yf[2]

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm, num_arcs=12)
    algo.set_derivative_jacobian(odejac)
    sol = Trajectory()
    sol.t = np.linspace(0, 1, 2)
    sol.y = np.array([[0, 0, 0, 0], [0, 0, 0, 0]])
    sol.k = np.array([const])
    # noinspection PyTypeChecker
    cc = np.linspace(const * 10, const, 10)
    for c in cc:
        sol = copy.deepcopy(sol)
        sol.k = np.array([c])
        sol = algo.solve(sol)['traj']

    assert sol.converged
예제 #10
0
def test_t21(algorithm, const):
    def odefun(y, _, k):
        return y[1], (y[0] * (1 + y[0]) - np.exp(-2 * y[2] / np.sqrt(k[0]))) / k[0], 1

    def odejac(y, _, k):
        df_dy = np.array([[0, 1, 0],
                          [(2*y[0] + 1) / k[0], 0, (2 * np.exp(-(2 * y[2]) / np.sqrt(k[0]))) / k[0] ** (3 / 2)],
                          [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, k):
        return y0[0] - 1, yf[0] - np.exp(-1 / np.sqrt(k[0])), y0[2]

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 0, 0], [0, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = np.exp(-sol.y[:, 2] / np.sqrt(const))
    e2 = -np.exp(-sol.y[:, 2] / np.sqrt(const)) / np.sqrt(const)
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #11
0
def test_t30(algorithm, const):
    def odefun(y, _, k):
        return y[1], (y[0] - y[0]*y[1]) / k[0]

    def odejac(y, _, k):
        df_dy = np.array([[0, 1], [(1-y[1]) / k[0], -y[0] / k[0]]])
        df_dp = np.empty((2, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0] + 7/6, yf[0] - 3/2

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm, num_arcs=8)
    algo.set_derivative_jacobian(odejac)
    sol = Trajectory()
    sol.t = np.linspace(0, 1, 2)
    sol.y = np.array([[-7/6, 0], [3/2, 0]])
    sol.k = np.array([const])
    # noinspection PyTypeChecker
    cc = np.linspace(const * 10, const, 10)
    for c in cc:
        sol = copy.deepcopy(sol)
        sol.k = np.array([c])
        sol = algo.solve(sol)['traj']

    assert sol.converged
예제 #12
0
def test_t7(algorithm, const):
    def odefun(y, _, k):
        return 2 * y[1], 2 * ((-y[2] * y[1] + y[0] - (1.0e0 + k[0] * np.pi ** 2) * np.cos(np.pi * y[2]) - np.pi *
                               y[2] * np.sin(np.pi * y[2])) / k[0]), 2

    def odejac(y, _, k):
        df_dy = np.array([[0, 2, 0],
                          [2 / k[0], -2 * y[2] / k[0],
                           -(2 * (y[1] + np.pi * np.sin(np.pi * y[2]) + np.pi ** 2 * y[2] * np.cos(np.pi * y[2])
                                  - np.pi * np.sin(np.pi * y[2]) * (k[0] * np.pi ** 2 + 1))) / k[0]],
                          [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0] + 1, yf[0] - 1, y0[2] + 1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[-1, 0, -1], [1, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = np.cos(np.pi * sol.y[:, 2]) + sol.y[:, 2] + (
                sol.y[:, 2] * erf(sol.y[:, 2] / np.sqrt(2.0e0 * sol.k[0]))
                + np.sqrt(2 * sol.k[0] / np.pi) * np.exp(-sol.y[:, 2] ** 2 / (2 * sol.k[0]))) / (
                 erf(1.0e0 / np.sqrt(2 * sol.k[0])) + np.sqrt(2.0e0 * sol.k[0] / np.pi)
                 * np.exp(-1 / (2 * sol.k[0])))
    e2 = erf((np.sqrt(2) * sol.y[:, 2]) / (2 * np.sqrt(sol.k[0]))) / (
            erf(np.sqrt(2) / (2 * np.sqrt(sol.k[0]))) + (np.sqrt(2) * np.sqrt(sol.k[0])) / (
                    np.sqrt(np.pi) * np.exp(1 / (2 * sol.k[0])))) - np.pi * np.sin(np.pi * sol.y[:, 2]) + 1
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #13
0
def test_t17(algorithm, const):
    def odefun(y, _, k):
        return 0.2 * y[1], 0.2 * (-3 * k[0] * y[0] / (k[0] + y[2] ** 2) ** 2), 0.2

    def odejac(y, _, k):
        df_dy = np.array([[0, 0.2, 0],
                          [-(3 * k[0]) / (5 * (y[2] ** 2 + k[0]) ** 2), 0, (12 * k[0] * y[0] * y[2])
                           / (5 * (y[2] ** 2 + k[0]) ** 3)], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, k):
        return y0[0] + 0.1 / np.sqrt(k[0] + 0.01), yf[0] - 0.1 / np.sqrt(k[0] + 0.01), y0[2] + 0.1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 0, 0], [0, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = sol.y[:, 2]/np.sqrt(sol.k[0] + sol.y[:, 2] ** 2)
    e2 = 1 / np.sqrt(sol.y[:, 2] ** 2 + sol.k[0]) - sol.y[:, 2] ** 2 / (sol.y[:, 2] ** 2 + sol.k[0]) ** (3 / 2)
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #14
0
def test_t24(algorithm, const):
    def odefun(x, _, k):
        a_mat_x = 1 + x[2] ** 2
        a_mat_xp = 2 * x[2]
        y = 1.4
        return (x[1], (((1 + y) / 2 - k[0] * a_mat_xp) * x[0] * x[1] - x[1] / x[0] - (a_mat_xp / a_mat_x) * (
                1 - (y - 1) / 2 * x[0] ** 2)) / (k[0] * a_mat_x * x[0]), 1)

    def odejac(x, _, k):
        y = 1.4
        df_dy = np.array(
            [[0, 1, 0],
             [(x[1] * (y / 2 - 2 * k * x[2] + 1 / 2) + x[1] / x[0] ** 2
               + (4 * x[0] * x[2] * (y / 2 - 1 / 2)) / (x[2] ** 2 + 1)) / (k[0] * x[0] * (x[2] ** 2 + 1))
              - ((2 * x[2] * ((y / 2 - 1 / 2) * x[0] ** 2 - 1)) / (x[2] ** 2 + 1) - x[1] / x[0] + x[0] * x[1]
                 * (y / 2 - 2 * k[0] * x[2] + 1 / 2)) / (k[0] * x[0] ** 2 * (x[2] ** 2 + 1)),
              (x[0] * (y / 2 - 2 * k[0] * x[2] + 1 / 2) - 1 / x[0]) / (k[0] * x[0] * (x[2] ** 2 + 1)),
              -((4 * x[2] ** 2 * ((y / 2 - 1 / 2) * x[0] ** 2 - 1)) / (x[2] ** 2 + 1) ** 2
                - (2 * ((y / 2 - 1 / 2) * x[0] ** 2 - 1)) / (x[2] ** 2 + 1) + 2 * k[0] * x[0] * x[1])
              / (k[0] * x[0] * (x[2] ** 2 + 1))
              - (2 * x[2] * ((2 * x[2] * ((y / 2 - 1 / 2) * x[0] ** 2 - 1))
                             / (x[2] ** 2 + 1) - x[1] / x[0] + x[0] * x[1]
                             * (y / 2 - 2 * k[0] * x[2] + 1 / 2))) / (k[0] * x[0] * (x[2] ** 2 + 1) ** 2)],
             [0, 0, 0]])
        df_dp = np.empty((3, 0))

        return df_dy, df_dp

    def bcfun(x0, xf, _, __, ___):
        return x0[0] - 0.9129, xf[0] - 0.375, x0[2]

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm, num_arcs=4)
    algo.set_derivative_jacobian(odejac)
    sol = Trajectory()
    sol.t = np.linspace(0, 1, 2)
    sol.y = np.array([[1, 1, 0], [0.1, 0.1, 1]])
    sol.k = np.array([const])
    # noinspection PyTypeChecker
    cc = np.linspace(const*10, const, 10)
    for c in cc:
        sol = copy.deepcopy(sol)
        sol.k = np.array([c])
        sol = algo.solve(sol)['traj']

    assert sol.converged
예제 #15
0
def test_t29(algorithm, const):
    def odefun(y, _, k):
        return y[1], (y[0] - y[0]*y[1]) / k[0]

    def odejac(y, _, k):
        df_dy = np.array([[0, 1], [(1-y[1]) / k[0], -y[0] / k[0]]])
        df_dp = np.empty((2, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0], yf[0] - 3/2

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm, num_arcs=1)
    algo.set_derivative_jacobian(odejac)
    sol = Trajectory()
    sol.t = np.linspace(0, 1, 2)
    sol.y = np.array([[0, 0], [3/2, 0]])
    sol.k = np.array([const])
    sol = algo.solve(sol)['traj']

    assert sol.converged
예제 #16
0
def test_t23(algorithm, const):
    def odefun(y, _, k):
        return y[1], 1 / k[0] * np.sinh(y[0] / k[0])

    def odejac(y, _, k):
        df_dy = np.array([[0, 1], [np.cosh(y[0] / k[0]) / k[0] ** 2, 0]])
        df_dp = np.empty((2, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0], yf[0] - 1

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 0], [1, 0]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    assert sol.converged
예제 #17
0
def test_t19(algorithm, const):
    def odefun(y, _, k):
        return y[1], (-y[1] / k[0]), 1

    def odejac(_, __, k):
        df_dy = np.array([[0, 1, 0], [0, -1 / k[0], 0], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, ___):
        return y0[0], yf[0], y0[2]

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 0, 0], [0, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    assert sol.converged
예제 #18
0
def test_t18(algorithm, const):
    def odefun(y, _, k):
        return y[1], (-y[1] / k[0]), 1

    def odejac(_, __, k):
        df_dy = np.array([[0, 1, 0], [0, -1 / k[0], 0], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, k):
        return y0[0] - 1, yf[0] - np.exp(-1 / k[0]), y0[2]

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 0, 0], [0, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = np.exp(-sol.y[:, 2] / sol.k[0])
    e2 = -1 / (sol.k[0] * np.exp(sol.y[:, 2] / sol.k[0]))
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)
예제 #19
0
def test_t16(algorithm, const):
    def odefun(y, _, k):
        return 1 * y[1], 1 * (-y[0] * np.pi ** 2 / (4 * k[0])), 1

    def odejac(_, __, k):
        df_dy = np.array([[0, 1, 0], [-np.pi**2 / (4 * k[0]), 0, 0], [0, 0, 0]])
        df_dp = np.empty((3, 0))
        return df_dy, df_dp

    def bcfun(y0, yf, _, __, k):
        return y0[0], yf[0] - np.sin(np.pi / (2 * np.sqrt(k[0]))), y0[2]

    algo = Shooting(odefun, None, bcfun, algorithm=algorithm)
    algo.set_derivative_jacobian(odejac)
    solinit = Trajectory()
    solinit.t = np.linspace(0, 1, 2)
    solinit.y = np.array([[0, 0, 0], [0, 0, 1]])
    solinit.k = np.array([const])
    sol = algo.solve(solinit)['traj']

    e1 = np.sin(np.pi * sol.y[:, 2] / (2 * np.sqrt(sol.k[0])))
    e2 = (np.pi * np.cos((np.pi * sol.y[:, 2]) / (2 * np.sqrt(sol.k[0])))) / (2 * np.sqrt(sol.k[0]))
    assert all(e1 - sol.y[:, 0] < tol)
    assert all(e2 - sol.y[:, 1] < tol)