Beispiel #1
0
def plot_move_odeint():
    states = [array([x1, y1, vx1, vy1, x2, y2, vx2, vy2])]

    states = odeint(move_, states[-1], times)
    states = array(states)

    earth = [states[:,0], states[:,1]]
    jupiter = [states[:,4], states[:,5]]
    sun = mpimg.imread('sun.png')
    
    fig, ax = subplots()

    ax.imshow(sun, aspect='auto', extent=(-.1, .1, -.1, .1), zorder=1)
    e_mark0, = ax.plot(earth[0], earth[1], 'b-', lw=2, alpha=.4)
    e_mark1, = ax.plot(earth[0], earth[1], 'bo', ms=5, alpha=.4)

    j_mark0, = ax.plot(jupiter[0], jupiter[1], 'r-', lw=2, alpha=.4)
    j_mark1, = ax.plot(jupiter[0], jupiter[1], 'ro', ms=7, alpha=.4)

    legend( [(e_mark0, e_mark1), (j_mark0, j_mark1)],
            ['Earth Orbit:\t$m_{\mathcal{E}}='+str(m1)+'$',
             'Jupiter Orbit:\t$m_{\mathcal{J}}='+str(m2)+'$'],
             numpoints=1)

    configure(  ax=ax,
                title=r'$'+str(tf-t0)+'$ Years; $\Delta t='+str(dt)+'$',
                xlabel=r'Displacement (AU)',
                ylabel=r'Displacement (AU)',
                xbounds=None, ybounds=None)

    fig.suptitle('VODE - Orbit of Two Planets About a Fixed Star', size=30)
    fig.subplots_adjust(left=0.075, right=0.95, top=0.9, bottom=0.08)

    show()
Beispiel #2
0
def main():
    #~ State Variables
    t0 = 0
    tf = .3
    dt = .001
    times = arange(t0, tf + dt, dt)
    #/~ State Variables

    #~ Bullet-specific Variables
    name = '50 ATV BT'
    b = bullet(name, mass=50., bc=0.242, model=G1)
    #~/ Bullet-Specific Variables

    #~ Get Samples
    from sample_data import samples
    vm = samples[name]['v'][:, 1][0]
    sight = samples[name]['st'][:, 0][2]

    x = samples[name]['st'][:, 0]
    y = samples[name]['st'][:, 1]
    #/~ Get Samples

    #~ Integrate
    theta = find_angle(sight, vm, b, times)
    print "THETA:", theta

    y0 = [0., 0., vm * cos(theta), vm * sin(theta)]
    states = odeint(b.shoot, y0, times)
    states = array(states)
    #/~ Integrate

    #~ Plot
    fig, ax = subplots()

    r_mark, = ax.plot(x, y, 'ro-', alpha=.8)
    b_mark, = ax.plot(states[:, 0] / 3.,
                      states[:, 1] * 12.,
                      'b-',
                      lw=3,
                      alpha=.8)

    legend([r_mark, b_mark],
           ['Sample Trajectory', 'Simulated (' + str(b) + ')'],
           numpoints=1)

    configure(ax=ax,
              title=r'G1 Model of Remington .233 cartridge' + '\n' +
              r'$\theta\approx' + str(round(theta, 6)) + r'$ radians',
              xlabel=r'Horizontal Displacement (yards)',
              ylabel=r'Height (inches)',
              xbounds=None,
              ybounds=None)

    fig.suptitle('Bullet Trajectory Simulation', size=30)
    fig.subplots_adjust(left=0.05, right=0.95, top=0.9, bottom=0.08)

    show()
Beispiel #3
0
def main():
    #~ State Variables

    t0 = 0
    tf = 0.5
    dt = .001
    times = np.linspace(t0, tf, 200)
    #/~ State Variables

    #~ Bullet-specific Variables
    name = '50 ATV BT'
    b = bullet(name, mass=50, bc=0.242, model=G1)
    vtot = 3300  #
    theta = 0.05
    vxi = vtot * (cos(theta * pi / 180))
    vyi = vtot * (sin(theta * pi / 180))
    #~/ Bullet-Specific Variables

    #~ Integrate
    y0 = [0., 0., vxi, vyi]
    states = odeint(b.shoot, y0, times)
    states = array(states)
    #/~ Integrate

    #~ Get Samples
    from sample_data import samples
    x = samples[name]['st'][:, 0]
    #print len(x)
    y = samples[name]['st'][:, 1]
    #print len(y)
    #/~ Get Samples

    #~ Plot
    fig, ax = subplots()

    r_mark, = ax.plot(x, y, 'ro', alpha=.8)
    b_mark, = ax.plot(states[:, 0], states[:, 1] * 12., 'bo', lw=3, alpha=.8)

    legend([r_mark, b_mark],
           ['Sample Trajectory', 'Simulated (' + str(b) + ')'],
           numpoints=1)

    configure(ax=ax,
              title=r'G1 Model of Remington .233 cartridge',
              xlabel=r'Horizontal Displacement (yards)',
              ylabel=r'Height (inches)',
              xbounds=None,
              ybounds=None)

    fig.suptitle('Bullet Trajectory Simulation', size=30)
    fig.subplots_adjust(left=0.05, right=0.95, top=0.9, bottom=0.08)

    show()
Beispiel #4
0
def main():
    # ~ State Variables
    t0 = 0
    tf = 0.3
    dt = 0.001
    times = arange(t0, tf + dt, dt)
    # /~ State Variables

    # ~ Bullet-specific Variables
    name = "50 ATV BT"
    b = bullet(name, mass=50.0, bc=0.242, model=G1)
    # ~/ Bullet-Specific Variables

    # ~ Get Samples
    from sample_data import samples

    vm = samples[name]["v"][:, 1][0]
    sight = samples[name]["st"][:, 0][2]

    x = samples[name]["st"][:, 0]
    y = samples[name]["st"][:, 1]
    # /~ Get Samples

    # ~ Integrate
    theta = find_angle(sight, vm, b, times)
    print "THETA:", theta

    y0 = [0.0, 0.0, vm * cos(theta), vm * sin(theta)]
    states = odeint(b.shoot, y0, times)
    states = array(states)
    # /~ Integrate

    # ~ Plot
    fig, ax = subplots()

    r_mark, = ax.plot(x, y, "ro-", alpha=0.8)
    b_mark, = ax.plot(states[:, 0] / 3.0, states[:, 1] * 12.0, "b-", lw=3, alpha=0.8)

    legend([r_mark, b_mark], ["Sample Trajectory", "Simulated (" + str(b) + ")"], numpoints=1)

    configure(
        ax=ax,
        title=r"G1 Model of Remington .233 cartridge" + "\n" + r"$\theta\approx" + str(round(theta, 6)) + r"$ radians",
        xlabel=r"Horizontal Displacement (yards)",
        ylabel=r"Height (inches)",
        xbounds=None,
        ybounds=None,
    )

    fig.suptitle("Bullet Trajectory Simulation", size=30)
    fig.subplots_adjust(left=0.05, right=0.95, top=0.9, bottom=0.08)

    show()
Beispiel #5
0
def main():
    #~ State Variables
    
    t0 = 0; tf = 0.5; dt=.001;
    times = np.linspace(t0, tf, 200)
    #/~ State Variables

    #~ Bullet-specific Variables
    name = '50 ATV BT'
    b = bullet(name, mass=50, bc=0.242, model=G1)
    vtot = 3300 #
    theta = 0.05
    vxi = vtot*(cos(theta*pi/180))
    vyi = vtot*(sin(theta*pi/180))
    #~/ Bullet-Specific Variables

    #~ Integrate
    y0 = [0., 0., vxi, vyi]
    states = odeint(b.shoot, y0, times)
    states = array(states)
    #/~ Integrate

    #~ Get Samples
    from sample_data import samples
    x = samples[name]['st'][:,0]; #print len(x)
    y = samples[name]['st'][:,1]; #print len(y)
    #/~ Get Samples

    #~ Plot
    fig, ax = subplots()

    r_mark, = ax.plot(x, y, 'ro', alpha=.8)
    b_mark, = ax.plot(states[:,0], states[:,1]*12., 'bo', lw=3, alpha=.8)

    legend( [r_mark, b_mark],
            ['Sample Trajectory',
             'Simulated ('+str(b)+')'],
            numpoints=1)

    configure( ax=ax,
                title=r'G1 Model of Remington .233 cartridge',
                xlabel=r'Horizontal Displacement (yards)',
                ylabel=r'Height (inches)',
                xbounds=None, ybounds=None)

    fig.suptitle('Bullet Trajectory Simulation', size=30)
    fig.subplots_adjust(left=0.05, right=0.95, top=0.9, bottom=0.08)

    show()
Beispiel #6
0
def plot_conservation():
    fig, ax = subplots()
    tax = ax.twinx()

    atols = [.00001, .000001, .0000001]
    y0 = array([x1, y1, vx1, vy1, x2, y2, vx2, vy2])
    for i,atol in enumerate(atols):
        states = odeint(move_, y0, times, atol=atol)

        enrgy = []
        for state in states:
            enrgy.append(energy(state))

        am = []
        for state in states:
            am.append(angular_momentum(state))

        alpha = (i+1.) / (len(atols)+1.)
        e_mark, = ax.plot(times, enrgy, 'b--', lw=3, alpha=alpha)
        am_mark, = tax.plot(times, am, 'r--', lw=3, alpha=alpha)

        legend( [e_mark, am_mark],
                [r'$E = \frac{1}{2}m_1v_1^2 + \frac{1}{2}m_2v_2^2 - \frac{GMm_1}{r_1} - \frac{GMm_2}{r_2} - \frac{Gm_2m1}{r_21}$',
                 r'$L = m_1 \left( x_1 v_{y1} - y_1 v_{x1} \right) + m_2 \left( x_2 v_{y2} - y_2 v_{x2} \right)$'],
                 numpoints=1, loc='upper right')

    configure(  ax=ax,
                    title=r'Absolute Tolerances: '+str(atols),
                    xlabel=r'Time (years)',
                    ylabel=r'Energy (Joules)',
                    colors=('k', 'b'))

    configure(  ax=tax,
                    ylabel=r'Angular Momentum $\left(kg\frac{m^2}{s}\right)$',
                    xbounds=(t0,tf+dt), colors=('k', 'r'), suppress=True)

    fig.suptitle('Conservation of Energy and Angular Momentum', size=30)
    fig.subplots_adjust(left=0.075, right=0.95, top=0.9, bottom=0.08)

    show()