Пример #1
0
    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()
Пример #2
0
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!"
Пример #3
0
 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()
Пример #4
0
# some helper stuff
R = side_length * 0.5 # radius described as half the langth of one side of the current loop.
b_z_circular = lambda z: ( mu0_I * R ** 2 / ( 2 * ( z ** 2 + R ** 2 ) ** ( 1.5 ) ) )

# Part A:
y1_vectors = np.asarray( map( b_field, part_A_points ) )
y2 = map( b_z_circular, axis_points )
for ( label, i ) in zip( ( 'x', 'y', 'z' ), range( 3 ) ):
    title = 'Part A: B(' + label + ') for x = y = 0 (Numerical and Analytical) '
    y1 = np.hsplit( y1_vectors, 3 )[i]   # get z-axis points, in third column
    x_label = label
    graph = Grapher( title, subtitle, x_label, y_label, legend_loc )
    graph.add_data( axis_points, y1, 'Numerical: B for x = y = 0' )
    graph.add_data( axis_points, y2, 'Analytical: B for x = y = 0' )
    graph.save_to_file( '/tmp/' + 'A' + label + '.png' )

# Part B:
y1_vectors = np.asarray( map( b_field, part_B_points ) )
for ( label, i ) in zip( ( 'x', 'y', 'z' ), range( 3 ) ):
    title = 'Part B: B(' + label + ') for y=0, z=1'     
    y1 = np.hsplit( y1_vectors, 3 )[i]   # get x-axis points
    x_label = label
    graph = Grapher( title, subtitle, x_label, y_label, legend_loc )
    graph.add_data( axis_points, y1, 'Approximation: B for y=0, z=1' )
    #graph.show_figure()
    graph.save_to_file( '/tmp/' + 'B' + label + '.png' )

# Part C:
y1_vectors = np.asarray( map( b_field, part_C_points ) )
for ( label, i ) in zip( ( 'x', 'y', 'z' ), range( 3 ) ):