Esempio n. 1
0
def find_fixedpoints_normal(xmin=-10.0,
                            xmax=10.0,
                            xstep=1e-3,
                            alpha=-0.41769,
                            beta=-0.346251775,
                            plot=False):

    no = NormalOscillator()

    xrng = np.arange(xmin, xmax + xstep, xstep)
    nullx = np.array([no.nullcline_x(xval, alpha, beta) for xval in xrng])

    xp = zip(xrng, nullx, np.abs(nullx))
    xp.sort(key=operator.itemgetter(-1))

    top3 = np.array(xp[:3])

    f = lambda x: no.nullcline_x(x, alpha, beta)
    df = lambda x: no.nullcline_dx(x, alpha, beta)

    zero_tol = 1e-6
    x_tol = 1e-4
    roots = list()
    for k, xi in enumerate(top3[:, 0]):
        try:
            xz = newton(f, xi, fprime=df, maxiter=100)
        except RuntimeError:
            continue
        xz_val = no.nullcline_x(xz, alpha, beta)
        #print 'xz=%0.9f, xz_val=%0.9f' % (xz, xz_val)
        if np.abs(xz_val) < zero_tol:
            is_duplicate = False
            for x, xv in roots:
                if np.abs(x - xz) < x_tol:
                    is_duplicate = True
            if not is_duplicate:
                #print 'Root: x=%0.6f, f(x)=%0.6f' % (xz, xz_val)
                roots.append([xz, xz_val])
    roots = np.array(roots)

    if plot:
        plt.figure()
        plt.plot(xrng, nullx, 'k-')
        plt.plot(top3[:, 0], top3[:, 1], 'rx')
        plt.plot(roots[:, 0], roots[:, 1], 'go')
        plt.title('Fixed Point Surface for dv')
        plt.xlabel('x')
        plt.axis('tight')

    return roots