Ejemplo n.º 1
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    file_prefix = None
    a = 16.0
    r = 45.0
    b = 4.0

    suffixed = lambda s, suf: None if s is None else '{0}{1}'.format(s, suf)

    try:
        options, args = getopt.getopt(argv[1:], 'a:r:b:f:')
        for opt, arg in options:
            if opt == '-a':
                a = float(arg)
            elif opt == '-r':
                r = float(arg)
            elif opt == '-b':
                b = float(arg)
            elif opt == '-f':
                file_prefix = arg
    except getopt.GetoptError as err:
        print str(err)
        return 2

    x0 = numpy.array([-13, -12, 52], dtype=numpy.float64)
    lfunc = lorenz(a, r, b)
    ts, xs = rungekutta.ark4(lfunc, 0.0, x0, 20000.0, 0.00001)
    plot.render3d(xs[0, :],
                  xs[1, :],
                  xs[2, :],
                  'b.',
                  xlabel='x',
                  ylabel='y',
                  zlabel='z',
                  markersize=0.2,
                  title='Lorenz Attractor',
                  file_prefix=suffixed(file_prefix, '_2a'))

    ts1, xs1 = rungekutta.ark4(lfunc, 0.0, x0, 2.0, 0.01)
    ts2, xs2 = rungekutta.rk4(lfunc, 0.0, x0, 0.001, 2000)

    def _lorenz_2b_callback(axes):
        axes.plot(xs1[0, :], xs1[1, :], xs1[2, :], 'b', label='ARK4')
        axes.plot(xs2[0, :], xs2[1, :], xs2[2, :], 'r', label='RK4')
        axes.legend()

    plot.render3d(xlabel='x',
                  ylabel='y',
                  zlabel='z',
                  title='RK4 vs. ARK4 Overlay',
                  ax_callback=_lorenz_2b_callback,
                  file_prefix=suffixed(file_prefix, '_2b'))

    return 0
Ejemplo n.º 2
0
def main(argv=None):
    if argv is None:
        argv=sys.argv        

    file_prefix = None
    a = 16.0
    r = 45.0
    b = 4.0

    suffixed = lambda s, suf: None if s is None else '{0}{1}'.format(s, suf)

    try:
        options, args = getopt.getopt(argv[1:], 'a:r:b:f:')
        for opt, arg in options:
            if opt == '-a':
                a = float(arg)
            elif opt == '-r':
                r = float(arg)
            elif opt == '-b':
                b = float(arg)
            elif opt == '-f':
                file_prefix = arg
    except getopt.GetoptError as err:
        print str(err)
        return 2

    x0 = numpy.array([-13, -12, 52], dtype=numpy.float64)
    lfunc = lorenz(a, r, b)
    ts, xs = rungekutta.ark4(lfunc, 0.0, x0, 20000.0, 0.00001)
    plot.render3d(
                xs[0,:], xs[1,:], xs[2,:], 'b.',
                xlabel='x', 
                ylabel='y', 
                zlabel='z', 
                markersize=0.2,
                title='Lorenz Attractor',
                file_prefix=suffixed(file_prefix, '_2a')
            )

    ts1, xs1 = rungekutta.ark4(lfunc, 0.0, x0, 2.0, 0.01)
    ts2, xs2 = rungekutta.rk4(lfunc, 0.0, x0, 0.001, 2000)
    def _lorenz_2b_callback(axes):
        axes.plot(xs1[0,:], xs1[1,:], xs1[2,:], 'b', label='ARK4')
        axes.plot(xs2[0,:], xs2[1,:], xs2[2,:], 'r', label='RK4')
        axes.legend()
    plot.render3d(
                xlabel='x', 
                ylabel='y', 
                zlabel='z', 
                title='RK4 vs. ARK4 Overlay',
                ax_callback=_lorenz_2b_callback,
                file_prefix=suffixed(file_prefix, '_2b')
            )

    return 0
Ejemplo n.º 3
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    file_prefix = None
    x = 0.0001
    y = 0.0001
    z = 0.0001

    a = 0.398
    b = 2.0
    c = 4.0

    try:
        options, args = getopt.getopt(argv[1:], 'f:x:y:z:a:b:c:')
        for opt, arg in options:
            if opt == '-f':
                file_prefix = arg
            elif opt == '-x':
                x = float(arg)
            elif opt == '-y':
                y = float(arg)
            elif opt == '-z':
                z = float(arg)
            elif opt == '-a':
                a = float(arg)
            elif opt == '-b':
                b = float(arg)
            elif opt == '-c':
                c = float(arg)
    except getopt.GetoptError as err:
        print str(err)
        return 2

    rfunc = rossler(a, b, c)
    x0 = numpy.array([x, y, z], numpy.float64)
    _, xs = rungekutta.ark4(rfunc, 0.0, x0, 20000.0, 0.00001)
    plot.render3d(xs[0, :],
                  xs[1, :],
                  xs[2, :],
                  'r.',
                  xlabel='x',
                  ylabel='y',
                  zlabel='z',
                  markersize=0.2,
                  title='Rossler Attractor',
                  file_prefix=file_prefix)
    return 0
Ejemplo n.º 4
0
def plot_dtol(tstep, **kwargs):
    '''
    Makes a plot with a parameterized tolerance.

    '''
    lfunc = lorenz(16.0, 45.0, 4.0)
    x0 = numpy.array([-13, -12, 52], dtype=numpy.float64)
    _, xs = rungekutta.ark4(lfunc, 0.0, x0, 20.0, tstep)
    plot_args = dict(kwargs)
    plot_args.update({
        'xlabel': 'x',
        'ylabel': 'y',
        'zlabel': 'z',
        'title': 'Lorenz Attractor (Tol = {0})'.format(tstep),
    })
    plot.render3d(xs[0, :], xs[1, :], xs[2, :], **plot_args)
Ejemplo n.º 5
0
def plot_dtol(tstep, **kwargs):
    '''
    Makes a plot with a parameterized tolerance.

    '''
    lfunc = lorenz(16.0, 45.0, 4.0)
    x0 = numpy.array([-13, -12, 52], dtype=numpy.float64)
    _, xs = rungekutta.ark4(lfunc, 0.0, x0, 20.0, tstep)
    plot_args = dict(kwargs)
    plot_args.update({
            'xlabel': 'x',
            'ylabel': 'y',
            'zlabel': 'z',
            'title': 'Lorenz Attractor (Tol = {0})'.format(tstep),
        })
    plot.render3d(xs[0,:], xs[1,:], xs[2,:], **plot_args)
Ejemplo n.º 6
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    file_prefix = None
    x = 0.0001
    y = 0.0001
    z = 0.0001

    a = 0.398
    b = 2.0
    c = 4.0

    try:
        options, args = getopt.getopt(argv[1:], 'f:x:y:z:a:b:c:')
        for opt, arg in options:
            if opt == '-f':
                file_prefix = arg
            elif opt == '-x':
                x = float(arg)
            elif opt == '-y':
                y = float(arg)
            elif opt == '-z':
                z = float(arg)
            elif opt == '-a':
                a = float(arg)
            elif opt == '-b':
                b = float(arg)
            elif opt == '-c':
                c = float(arg)
    except getopt.GetoptError as err:
        print str(err)
        return 2

    rfunc = rossler(a, b, c)
    x0 = numpy.array([x, y, z], numpy.float64)
    _, xs = rungekutta.ark4(rfunc, 0.0, x0, 20000.0, 0.00001)
    plot.render3d(xs[0,:], xs[1,:], xs[2,:], 'r.', 
                xlabel='x',
                ylabel='y',
                zlabel='z',
                markersize=0.2,
                title='Rossler Attractor',
                file_prefix=file_prefix
            )
    return 0