예제 #1
0
    def newton_raphson(self, ox, oy, direction, step=1e-5):
        """
        Computes an iterate of NR

        Parameters
        ----------
        ox : float
            DESCRIPTION. 
        oy : float
            DESCRIPTION.
        direction : +/- 1
            DESCRIPTION. 1 for positive branch of unstable manifold. 
            -1 for negative
        step : TYPE, optional
            DESCRIPTION. The default is 1e-5.

        Returns
        -------
        PE/PE' : float
            DESCRIPTION. Error iterate

        """
        bmk = Bmk({'ox': ox, 'oy': oy})
        ode = Ode(bmk.ode)

        PE = ode.homoclinic_dist(direction, 'rotational')

        bmk_incr = Bmk({'ox': ox, 'oy': oy + step})
        ode_incr = Ode(bmk_incr.ode)

        PE_incr = ode_incr.homoclinic_dist(direction, 'rotational')
        return PE / ((PE_incr - PE) / step)
예제 #2
0
def newton_raphson(ox, oy, direction, step=1e-8):

    bmk = Bmk({'ox': ox, 'oy': oy})
    ode = Ode(bmk.ode)

    PE = ode.homoclinic_dist(direction, 'contractible')

    bmk_incr = Bmk({'ox': ox + step, 'oy': oy})
    ode_incr = Ode(bmk_incr.ode)

    PE_incr = ode_incr.homoclinic_dist(direction, 'contractible')
    return PE / ((PE_incr - PE) / step)
예제 #3
0
def jacobian(PE, ox, oy, step=1e-15):

    bmk = Bmk({'ox': ox + step, 'oy': oy})
    ode = Ode(bmk.ode)

    PE_x = ode.pontryagin_energy('rotational')

    bmk = Bmk({'ox': ox, 'oy': oy + step})
    ode = Ode(bmk.ode)

    PE_y = ode.pontryagin_energy('rotational')

    return np.array([[(PE_x[0] - PE[0]) / step, (PE_y[0] - PE[0]) / step],
                     [(PE_x[1] - PE[1]) / step, (PE_y[1] - PE[1]) / step]])
예제 #4
0
def periodic_counter(ox, oy, granularity=200):
    bmk = Bmk({'ox': ox, 'oy': oy})
    ode = Ode(bmk.ode)

    centre = ode.get_centre()
    saddle = ode.get_saddle_point()

    if centre[0]['x'] > saddle[0]['x']:

        theta = np.arctan((centre[0]['y'] - saddle[0]['y']) /
                          (centre[0]['x'] - saddle[0]['x']))

    else:

        theta = -np.pi + np.arctan((centre[0]['y'] - saddle[0]['y']) /
                                   (centre[0]['x'] - saddle[0]['x']))

    c = np.cos(theta)
    s = np.sin(theta)

    granularity = 80

    H_axis_x = np.linspace(centre[0]['x'], saddle[0]['x'], granularity)
    H_axis_y = np.linspace(centre[0]['y'], saddle[0]['y'], granularity)

    H_axis = list(zip(H_axis_x, H_axis_y))

    delta_H = []

    for (x_0, y_0) in H_axis:

        pt_dict = {'x': x_0, 'y': y_0}
        (x_0, y_0) = transform(x_0, y_0, c, s, centre)
        curve_x = [x_0]
        curve_y = [y_0]
        not_crossed = True
        looper = 0
        while not_crossed and looper < 50000:
            looper += 1
            pt_dict = ode._euler_iter(pt_dict, h=5e-3)
            pt_x, pt_y = transform(pt_dict['x'], pt_dict['y'], c, s, centre)

            if curve_y[-1] < -1e-12 and pt_y > 1e-12:
                not_crossed = False

            curve_x.append(pt_x)
            curve_y.append(pt_y)
        if np.abs(curve_y[-1]) < 1e-1 and curve_x[-1] < 1e-2:
            delta_H.append(x_0 - pt_x)
        else:
            #print('Escaped bounded region')
            break
    # plt.plot(curve_x, curve_y)
    #plt.show()
    po_count = 0
    index = []
    for H in range(10, len(delta_H) - 1):
        if np.sign(delta_H[H]) != np.sign(delta_H[H - 1]):
            po_count += 1
            index.append(H)

    if po_count == 2:

        return po_count, delta_H

    else:

        return po_count, delta_H
예제 #5
0
@author: Francesco
"""

import PyDSTool
#from numpy import (sin, cos, pi)
#from PyDSTool.Toolbox import phaseplane as pp
#import numpy as np
import matplotlib.pyplot as plt
from rhc_cont import Ode
import pickle
from bmk import Bmk
#from ode import Ode
from rhc_cont import RhcCont

bmk = Bmk({'ox': 0, 'oy': 0})
ode = bmk.get_ode()

#Setting Continuation class
PC = PyDSTool.ContClass(ode)


##########################################################
#
#
#
##########################################################
def inner_outer_init(PC):
    print("Initialising boundary")
    PCargs = PyDSTool.args(name='EQ1', type='EP-C')
    PCargs.freepars = ['ox']
예제 #6
0
    PE_x = ode.pontryagin_energy('rotational')

    bmk = Bmk({'ox': ox, 'oy': oy + step})
    ode = Ode(bmk.ode)

    PE_y = ode.pontryagin_energy('rotational')

    return np.array([[(PE_x[0] - PE[0]) / step, (PE_y[0] - PE[0]) / step],
                     [(PE_x[1] - PE[1]) / step, (PE_y[1] - PE[1]) / step]])


par = [-0.00964967, 0.92704312]
progress = [tuple(par)]
PE_progress = []

for i in range(100):
    bmk = Bmk({'ox': par[0], 'oy': par[1]})
    ode = Ode(bmk.ode)

    PE = ode.pontryagin_energy('rotational')

    jac = jacobian(PE, par[0], par[1])

    par -= 0.1 * np.matmul(np.linalg.inv(jac), np.array(PE))
    progress.append(tuple(par))
    PE_progress.append(sum(PE))
    print("Epoch:", i, " PE:", round(PE_progress[-1], 8))
#pickle.dump(progress, open('progress_08.p','wb'))
#plt.scatter(*zip(*progress))
plt.plot(PE_progress)
plt.show()
예제 #7
0
# -*- coding: utf-8 -*-
"""
Created on Fri May 29 18:43:12 2020

@author: Francesco
"""


import matplotlib.pyplot as plt
from ode import Ode
from bmk import Bmk
import numpy as np

bmk = Bmk({'ox': -0.009, 'oy': 0.927})
ode = Ode(bmk.ode)

fp = ode.get_fixed_points()
if ode.fp_eigen(fp[0]) in ['hyperbolic repeller', 'hyperbolic attractor']:
    centre = fp[0]
    saddle = fp[1]
else:
    centre = fp[1]
    saddle = fp[0]

H_axis_x = np.linspace(centre['x'],saddle['x']+1, 20)
H_axis_y = np.linspace(centre['y'],centre['y'], 20)

H_axis = list(zip(H_axis_x, H_axis_y))

예제 #8
0
    for index, val_pair in enumerate(zip(xs, ys)):
        if index != 0:
            if np.abs(xs[index] - xs[index - 1]) > break_threshold:
                xs_.append(None)
                ys_.append(None)
            if np.abs(ys[index] - ys[index - 1]) > break_threshold:
                xs_.append(None)
                ys_.append(None)
        xs_.append(val_pair[0])
        ys_.append(val_pair[1])

    return np.array(xs_), np.array(ys_)


bmk = Bmk({'ox': -0.16, 'oy': 1})
ode = Ode(bmk.ode)

P1, _ = ode.unstable_manifold(1)
P2, _ = ode.unstable_manifold(-1)

x_plt = []
y_plt = []
for i in range(len(P1)):
    (x, y) = ode._point_dict_getter(P1[i])
    x_plt.append(x)
    y_plt.append(y)

x_plt, y_plt = para_plot(np.array(x_plt) % 1, np.array(y_plt) % 1, 0.5)

x_plt_lift = []
예제 #9
0
Created on Sat Apr 25 21:57:51 2020

@author: Francesco
"""

import matplotlib.pyplot as plt
from ode import Ode
from bmk import Bmk
import numpy as np

ox = np.linspace(-1e-02, 0, 100)
tr_saddle = []
tr_node = []
#-0.009649961793522382], [0.9270432434144844
for i in ox:
    bmk = Bmk({'ox': i, 'oy': 0.9270432434144844})
    ode = Ode(bmk.ode)
    fp = ode.get_fixed_points()
    fp_type = ode.fp_eigen(fp[0])[0]
    if fp_type == 'saddle point':
        print('case saddle {}'.format(i))
        tr_saddle.append(ode.jacobian(fp[0])[0][0] + ode.jacobian(fp[0])[1][1])
        tr_node.append(ode.jacobian(fp[1])[0][0] + ode.jacobian(fp[1])[1][1])
    else:
        print('case node {}'.format(i))
        tr_saddle.append(ode.jacobian(fp[1])[0][0] + ode.jacobian(fp[1])[1][1])
        tr_node.append(ode.jacobian(fp[0])[0][0] + ode.jacobian(fp[0])[1][1])

#figure, axes = plt.subplots(nrows=2, ncols=1)
plt.plot(ox, tr_saddle)
#plt.plot(ox, [0]*len(ox))