def mag_oscillation(KE=.001): # print(KE) # p_phi1 = (KE/10.)**.5 #give half the KE to p_phi1 # p_phi2 = -p_phi1 # p_tht = 0. # T_long = 2*numpy.pi/((5./3.)**.5) p_phi1 = (KE / 18.)**.5 p_phi2 = p_phi1 p_tht = -2 * p_phi1 T_long = 2 * numpy.pi / ((7.)**.5) calced_KE = p_phi1**2 * 5 + p_phi2**2 * 5 + 2 * p_tht**2 print(calced_KE, KE) print(p_tht**2 / 2) print(T_long) init_state = numpy.array([0, 0, 0, 0, p_phi1, p_phi2, p_tht]) sim_path = utils.RK4_adapt(double_dipole_eqs, init_state, T_long * 2, max_steps=10**6, precision=10**-6) t_vals = utils.read_column(sim_path, 0) phi1_vals = numpy.array(utils.read_column(sim_path, 1)) phi2_vals = numpy.array(utils.read_column(sim_path, 2)) tht_vals = numpy.array(utils.read_column(sim_path, 3)) print(phi1_vals[-1] - tht_vals[-1]) pyplot.plot(t_vals, phi1_vals) pyplot.plot(t_vals, phi2_vals) pyplot.plot(t_vals, tht_vals) pyplot.show()
def frame_gen(energy): # del x_vals[:] # del y_vals[:] axes.clear() sim_path = simulate_energy(energy) t_vals = numpy.array(utils.read_column(sim_path, 0)) phi1_vals = numpy.array(utils.read_column(sim_path, 1)) phi2_vals = numpy.array(utils.read_column(sim_path, 2)) tht_vals = numpy.array(utils.read_column(sim_path, 3)) pyplot.plot(t_vals, phi1_vals) pyplot.plot(t_vals, phi2_vals) pyplot.plot(t_vals, tht_vals) axes.set_ylim(-2., 2.) axes.set_title('initial KE=%f' % energy)
def plot_all_variables(t, states): figure, subplots = pyplot.subplots(2,4) exp1 = 0.287723317652649 fits = [] figure.suptitle('residues of $\\phi_d$, $\\phi_t$, $\\theta$ and r. associated momenta plotted below. Green curve denotes expected curve from exponential growth.') for ti in t: row = [] for ind in range(len(states[0])): row.append([states[0][ind]*numpy.exp(exp1*ti)]) fits.append(row) # print(len(t), len(fits), utils.read_column(fits, 0)) for i in range(4): subplots[0][i].plot(t, utils.read_column(states,i)) # subplots[0][i].plot(t, utils.read_column(fits,i)) subplots[1][i].plot(t, utils.read_column(states,i+4)) pyplot.show()
def plot_path_from_point(state0): start = numpy.array(state0) figure, subplots = pyplot.subplots(1, 2) # print(start[-2:]) path = utils.RK4_adapt(reduced_double_dipole, start, 6., max_steps=10**6, precision=10**-7) t_vals = utils.read_column(path, 0) phid_vals = numpy.array(utils.read_column(path, 1)) phit_vals = numpy.array(utils.read_column(path, 2)) tht_vals = numpy.array(utils.read_column(path, 3)) pphid_vals = numpy.array(utils.read_column(path, 4)) pphit_vals = numpy.array(utils.read_column(path, 5)) ptht_vals = numpy.array(utils.read_column(path, 6)) force_r = numpy.array(map(rf_red, path)) ratio = numpy.array(map(lambda arr: arr[2] / arr[3], path)) # subplots[0].plot(t_vals ,phid_vals) # subplots[0].plot(t_vals ,phit_vals) # subplots[0].plot(t_vals ,tht_vals) subplots[0].plot(t_vals, force_r) # subplots[0].plot(t_vals ,ratio) #between phit and tht subplots[1].plot(t_vals, pphid_vals) subplots[1].plot(t_vals, pphit_vals) subplots[1].plot(t_vals, ptht_vals) pyplot.show()
def random_point_examine(): #phd, pht, tht, pd, pt, ptht state0p, state0m = utils.reduced_state_gen() figure, subplots = pyplot.subplots(2, 2) states = [state0p, state0m] print(state0p) for state0_ind in range(2): start = numpy.array(states[state0_ind]) print(start[-2:]) # print(start[-2:]) path = utils.RK4_adapt(reduced_double_dipole, start, 20., max_steps=10**6, precision=10**-7) t_vals = utils.read_column(path, 0) phid_vals = numpy.array(utils.read_column(path, 1)) phit_vals = numpy.array(utils.read_column(path, 2)) tht_vals = numpy.array(utils.read_column(path, 3)) pphid_vals = numpy.array(utils.read_column(path, 4)) pphit_vals = numpy.array(utils.read_column(path, 5)) ptht_vals = numpy.array(utils.read_column(path, 6)) force_r = numpy.array(map(rf_red, path)) subplots[state0_ind, 0].plot(t_vals, phid_vals) subplots[state0_ind, 0].plot(t_vals, phit_vals) subplots[state0_ind, 0].plot(t_vals, tht_vals) subplots[state0_ind, 0].plot(t_vals, force_r) subplots[state0_ind, 1].plot(t_vals, pphid_vals) subplots[state0_ind, 1].plot(t_vals, pphit_vals) subplots[state0_ind, 1].plot(t_vals, ptht_vals) pyplot.show()
def plot_period_vs_energy(): # plot spinning periods data_spinning = parse_file('./clean_spinnning_periods.txt') p_vals = utils.read_column(data_spinning, 0) sig_vals = utils.read_column(data_spinning, 1) E_vals = utils.read_column(data_spinning, 2) pyplot.plot(E_vals, p_vals, label='Large Amplitude Spinning Mode') T_s = numpy.pi * 2 * (5. / 3.)**(-.5) E_vals = numpy.linspace(-1. / 3., -1 / 5., 20) ones = numpy.ones(20) pyplot.plot(E_vals, T_s * ones, 'b--', label='Small Amplitude spinning mode') #plot orbital periods data_orbital = parse_file('./clean_orbital_periods.txt') p_vals = utils.read_column(data_orbital, 0) sig_vals = utils.read_column(data_orbital, 1) E_vals = utils.read_column(data_orbital, 2) p2_vals = map(lambda x: x * 2, p_vals) pyplot.plot(E_vals, p_vals, label='Large Amplitude Orbital Mode') # pyplot.plot(E_vals, p2_vals) # plot pendulum periods # E_p_vals_spin = spin_periods() # pyplot.plot(E_p_vals_spin[0], E_p_vals_spin[1]) #plot analytic low-amplitude T_o = numpy.pi * 2 * (7.)**(-.5) E_vals = numpy.linspace(-1. / 3., -0.2, 20) ones = numpy.ones(20) pyplot.plot(E_vals, T_o * ones, 'g--', label='Small Amplitude orbital mode') pyplot.xlabel('Energy $(U_0+T_0)$', fontsize=16) pyplot.ylabel('Period ', fontsize=16) pyplot.ylim(0, 12) pyplot.xlim(-1. / 3., 1. / 6.) pyplot.text((-0.3), 8, 'Spinning Mode') pyplot.text((-0.3), 3.25, 'Orbital Mode') # pyplot.text( # x=(-1/3.+.005), y=6., # text='S', size=15 # ) # pyplot.legend(loc='upper right') # pyplot.legend(handles = legend_elements, loc='upper right') pyplot.title('Large Amplitude Period vs System Energy', loc='left', fontsize=18) pyplot.savefig('plot.png') pyplot.show()