def testFig8Lce(self):  # takes a long time, so its disabled
        sys = NBodySystem(body_masses=[1, 1, 1], G=1)
        solver = SystemSolver(sys)
        tspan = [0, 1.5]
        y0 = np.zeros(2 * sys.body_dim * len(sys.body_masses),
                      dtype=np.float64)

        x1 = np.array([0.97000436, -0.24308753, 0])
        x3p = np.array([-0.93240737, -0.86473146, 0])

        y0[0:3] = x1
        y0[3:6] = -x1
        y0[6:9] = 0
        y0[9:12] = -x3p / 2
        y0[12:15] = -x3p / 2
        y0[15:18] = x3p
        # print(sys.fun(np.zeros_like(y0), y0).reshape(6, -1))
        lce, run = solver.get_lce(tspan[1], y0)
        t = run['results'].t[1:]
        y = run['results'].y[sys.dim:, 1:].reshape(sys.dim, sys.dim, -1)
        #print(y[:, :, -1])
        lces = []
        for i, t_val in enumerate(t):
            Df_y = y[:, :, i]
            lces.append(solver.calc_lce(Df_y, t_val))
        print(lces[-1])
        print(np.mean(lces[-5:]))
        clearFigs()
        plt.figure()
        plt.plot(t, lces)
        plt.show(True)
 def testExample(self):
     sys = RestrictedCircular3Body()
     slv = SystemSolver(sys)
     lce, lce_run = slv.get_lce()
     slv.calc_lce
     # print(lce)
     init = [1, -1, 1, -1]
     run = slv.run([0, 5], init)
     run['results'].y = run['results'].y[:2, :]
     slv.plot2d(run)
示例#3
0
 def testLCEPendulumLong(self):
     sys = DoublePendulumSystem()
     slv = SystemSolver(sys)
     theta = pi * 120 / 180
     lce, run = slv.get_lce(T=100, y0=[theta, 0, 0, 0])
     y = run['results'].y
     Df_y0 = y[sys.dim:, -1].reshape(sys.dim, sys.dim)
     print(Df_y0)
     print(lce)
     self.assertGreater(lce, 0)
示例#4
0
 def testLCEPendulumVaryAngle(self):
     sys = DoublePendulumSystem()
     slv = SystemSolver(sys)
     thetas = []
     lces = []
     for theta in np.arange(0.001, pi + 0.0001, pi / 20):
         lce, _ = slv.get_lce(T=100, y0=[theta, 0, 0, 0])
         thetas.append(theta)
         lces.append(lce)
     clearFigs()
     plt.figure()
     plt.plot(thetas, lces)
     plt.show(True)
 def testLCE(self):
     # slv.calc_lce(Df_y0, T)
     sys = RestrictedCircular3Body()
     slv = SystemSolver(sys)
     lce, lce_run = slv.get_lce(T=100)
     t = lce_run['results'].t
     y = lce_run['results'].y
     sys_dim = sys.dim
     lces = []
     start_t = 10
     for i in range(start_t, t.shape[0]):
         Df_y0 = y[sys_dim:, i].reshape(sys_dim, sys_dim)
         lce = slv.calc_lce(Df_y0, t[i])
         lces.append(lce)
     plt.plot(t[start_t:], lces)
     plt.show(True)
示例#6
0
 def runLCETest(self, sigma, rho, beta, l1):
     sys = LorenzSystem(sigma, rho, beta)
     slv = SystemSolver(sys)
     lce, run = slv.get_lce(T=100)
     T0 = 0
     t = run['results'].t[T0:]
     y = run['results'].y[:, T0:]
     lces = []
     for i, t_val in enumerate(t):
         Df_y0 = y[sys.dim:, i].reshape(sys.dim, sys.dim)
         lces.append(slv.calc_lce(Df_y0, t_val))
     clearFigs()
     plt.figure()
     plt.plot(t, lces)
     plt.show(True)
     print(Df_y0)
     print(lce, l1, (lce - l1) / l1)
     self.assertAlmostEqual((lce - l1) / l1, 0, places=0)
示例#7
0
from echonn.sys import CircleSystem, SystemSolver

if __name__ == "__main__":
    sys = SystemSolver(CircleSystem())
    lce, run = sys.get_lce()
    print('lce:', lce)
    print(run['results'].y[2:, -1].reshape(2, 2))
示例#8
0
if __name__ == "__main__":
    data = [
        [16, 45.92, 4, 1.50255],
        [16, 40, 4, 1.37446],
        [10, 28, 8 / 3, 0.90566],
    ]
    results = []
    for sigma, rho, beta, lambda_ in data:

        lces = []
        print('calculating lces...')
        for i in range(10):
            sys = LorenzSystem(sigma, rho, beta)
            slv = SystemSolver(sys)

            lce, _ = slv.get_lce()
            print('\t{}:'.format(i), lce)
            lces.append(lce)
        res = {}
        res['beta'] = beta
        res['rho'] = rho
        res['sigma'] = sigma
        res['lambda'] = lambda_
        res['mean'] = np.mean(lces)
        res['std'] = np.std(lces)
        res['error'] = res['mean'] - lambda_
        res['relative error'] = res['error'] / lambda_
        print(res)
        print()
        results.append(res)
示例#9
0
solver = SystemSolver(sys)
tspan = [0, 200]
y0 = np.zeros(2 * sys.body_dim * len(sys.body_masses), dtype=np.float64)

x1 = np.array([0.97000436, -0.24308753])
x3p = np.array([-0.93240737, -0.86473146])

y0[0:2] = x1
y0[2:4] = -x1
# y0[4:6] = zero
y0[6:8] = -x3p / 2
y0[8:10] = -x3p / 2
y0[10:12] = x3p

# print(sys.fun(np.zeros_like(y0), y0).reshape(6, -1))
lce, run = solver.get_lce(tspan[1], y0)
t = run['results'].t[1:]
y = run['results'].y[sys.dim:, 1:].reshape(sys.dim, sys.dim, -1)
#print(y[:, :, -1])
lces = []
for i, t_val in enumerate(t):
    Df_y = y[:, :, i]
    lces.append(solver.calc_lce(Df_y, t_val))

plt.figure()
plt.title(f'LCE ({lces[-1]:.2}) Convergence for 3 Body Figure 8')
plt.plot(t, lces)
plt.ylabel('LCE')
plt.xlabel('t')
plt.savefig(os.path.join(dir_pre, 'lce_converge.png'))
# plt.show(True)
import numpy as np
import os
from echonn.sys import DoublePendulumSystem, SystemSolver
import matplotlib.pyplot as plt
from scipy.constants import pi

if __name__ == "__main__":
    sys = DoublePendulumSystem()
    slv = SystemSolver(sys)
    thetas = np.arange(0.001, pi + 0.0001, pi / 20)
    out_img = os.path.join('..', 'images', 'chaos_vs_energy_in_doub_pend.png')
    lces = []
    for theta in thetas:
        lce, _ = slv.get_lce(T=200, y0=[theta, 0, 0, 0])
        lces.append(lce)
    plt.title('Largest LCE vs Inner Theta IC')
    plt.xlabel('Inner Theta')
    plt.ylabel('Largest LCE')
    plt.plot(180 * thetas / pi, lces)
    try:
        if os.path.exists(out_img):
            os.remove(out_img)
    except:
        pass  # don't worry about it
    plt.savefig(out_img)
    plt.show(True)
示例#11
0
import numpy as np
import matplotlib.pyplot as plt
from echonn.sys import SystemSolver, RestrictedCircular3Body, LyapunovSystem

if __name__ == "__main__":
    mu = 0.5
    sys = RestrictedCircular3Body(body_ratio=mu)
    lce = LyapunovSystem(sys)

    #init = [1, -1, .1, .1]
    init = np.array(1000 * np.random.rand(4), dtype=int) / 1000
    slv = SystemSolver(sys)
    #run = slv.run([0, 10], init, max_step=0.001)
    T = 100
    lce, run = slv.get_lce(T=T, y0=init)
    #lce, run = slv.get_lce(T=T)
    mat = run['results'].y[4:, -1].reshape(4, 4)
    run['results'].y = run['results'].y[[0, 2], :]
    slv.plot2d(run)
    plt.scatter([-sys.alpha, sys.mu], [0, 0])
    print(init)
    print(mat)
    print('lce:', lce)
    #plt.xlim((-15, 15))
    #plt.ylim((-15, 15))
    # Saved manually since it can't be scripted
    plt.show(True)
示例#12
0
 def testCircleLCE(self):
     sys = SystemSolver(CircleSystem())
     lce, run = sys.get_lce()
     self.assertAlmostEqual(lce, 0, places=4)
示例#13
0
 def testLCEPendulum(self):
     sys = DoublePendulumSystem()
     slv = SystemSolver(sys)
     slv.get_lce(T=2, y0=[1.8, 1.8, 0, 0])
示例#14
0
 def runLCETestShort(self, sigma, rho, beta, l1):
     sys = LorenzSystem(sigma, rho, beta)
     slv = SystemSolver(sys)
     slv.get_lce(T=2)