def plot_N_iter_with_error( self ): N_iters, errors = self.N_iters, self.errors N_iter_with_error = Grapher( "V(r): N_iter vs. error", '', 'N_iter, the number of relaxations', 'error', 'upper right' ) N_iter_with_error.add_data_scatter( N_iters, errors, 'Error = Sum(squared differences of phi[i][j], between iterations' ) # N_iter_with_error.ax.set_ylim( 0, 2e-5 ) N_iter_with_error.save_to_file( '/tmp/N_iter_with_error2.png' ) N_iter_with_error.show_figure()
t_points = linspace( 0, T, n + 1 ) # should I make this a numpy array? u0_graph = Grapher( 'Theta(t)', '', 't (seconds)', 'theta (radians)', 'bottom right' ) #title, subtitle, x_label, y_label, legend_loc u1_graph = Grapher( 'Omega(t)', '', 't (seconds)', 'omega (radians per second)', 'bottom right' ) for f in pendula: method = method_class( f ) method.set_initial_condition( U0 ) #TODO: how do I want to store results for comparing results by omega_D? u, t = method.solve( t_points ) # u(t) is a 2 x n array with [u0,u1] for all t's u0_values = u[:, 0] # get the u0 values from u for plotting u0_graph.add_data( t, u0_values, str( f.omega_D ) ) u1_values = u[:, 1] u0_graph.add_data( t, u1_values, str( f.omega_D ) ) # u0_graph.show_figure() u1_graph.show_figure() for method_class, color in [( ODE_Solver_v3.RungeKutta2, 'r-' ), ( ODE_Solver_v3.EulerCromer, 'b-' )]: npoints_per_period = 500 n = npoints_per_period * nperiods t_points = linspace( 0, T, n + 1 ) # should I make this a numpy array? # figure( 'theta' ) # make figure for theta(t) fig_u0 = figure( 1 ) # make figure for theta(t) # figure( 'omega' ) # and for omega(t) fig_u1 = figure( 2 ) # make figure for theta(t) #plot models for each driving frequency for f in pendula: method = method_class( f ) method.set_initial_condition( U0 ) #TODO: how do I want to store results for comparing results by omega_D? u, t = method.solve( t_points )
def plot_V_of_r( self ): r, V = self.get_V_of_r() graph = Grapher( "V(r): Electric Potential of a Static Dipole", '', 'radius from origin', 'Potential', 'upper right' ) graph.add_data_scatter( r, V, 'V(r)' ) graph.save_to_file( '/home/res/Documents/duke/2012S/PHY260/midterm/V_r.png' ) graph.show_figure()
for jac_grid in jac_grids: jac_grid.solve_jacobi( epsilon, N_iter_max ) # print 'hi' jac_N_iters_list.append( jac_grid.N_iter ) for sor_grid in sor_grids: sor_grid.solve_SOR( epsilon, N_iter_max, accuracy ) # print 'hey' sor_N_iters_list.append( sor_grid.N_iter ) # make plot figure of results title = 'N iterations vs. n | SOR, Jacobi compared.' subtitle = '' x_label = 'n = sites on grid' y_label = 'N = number of iterations' legend_loc = 'upper left' graph = Grapher( title, subtitle, x_label, y_label, legend_loc ) graph.add_data( n_list, jac_N_iters_list, 'Jacobi' ) graph.add_data( n_list, sor_N_iters_list, 'SOR' ) graph.save_to_file( '/home/res/Documents/duke/2012S/PHY260/midterm/jac_sor_' + time_string() + '.png' ) # save the data to be plotted np.save( '/home/res/Documents/duke/2012S/PHY260/midterm/jac_N_iter_vs_n_' + time_string(), np.asarray( zip( n_list, jac_N_iters_list ) ) ) np.save( '/home/res/Documents/duke/2012S/PHY260/midterm/sor_N_iter_vs_n_' + time_string(), np.asarray( zip( n_list, sor_N_iters_list ) ) ) # show the plot graph.show_figure() print "Done with midterm_Dipole.py!"