#! /usr/bin/env python3 # def damped_sine_plot ( ): #*****************************************************************************80 # ## damped_sine_plot() plots the damped sine correlation function. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 23 September 2026 # # Author: # # John Burkardt # import matplotlib import numpy as np import platform print ( '' ) print ( 'damped_sine_plot():' ) print ( ' matplotlib version: ' + matplotlib.__version__ ) print ( ' numpy version: ' + np.version.version ) print ( ' python version: ' + platform.python_version ( ) ) print ( ' damped_sine_plot() plots the damped sine correlation function.' ) # # Define the damped_sine data. # rho0 = 1.0 n = 101 rho = np.linspace ( -12.0, +12.0, n ) c = np.ones ( n ) i = np.where ( rho != 0.0 ) c[i] = rho0 * np.sin ( np.abs ( rho[i] ) / rho0 ) / np.abs ( rho[i] ) # # Request a plot. # correlation_plot ( n, rho, c, 'damped_sine', 'Damped sine correlation' ) return def correlation_plot ( n, rho, c, header, title ): #*****************************************************************************80 # ## correlation_plot() makes a plot of a correlation function. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 04 January 2013 # # Author: # # John Burkardt # # Input: # # integer N, the number of arguments. # # real RHO(N), the arguments. # # real C(N), the correlations. # # string HEADER, an identifier for the files. # # string TITLE, a title for the plot. # data_filename = header + '_data.txt' data_unit = open ( data_filename, 'wt' ) for i in range ( 0, n ): s = ( ' %14.6g %14.6g\n' % ( rho[i], c[i] ) ) data_unit.write ( s ) data_unit.close ( ) print ( ' Created data file "' + data_filename + '"' ) command_filename = header + '_commands.txt' command_unit = open ( command_filename, 'wt' ) command_unit.write ( '# ' + command_filename + '\n' ) command_unit.write ( '#\n' ) command_unit.write ( '# Usage:\n' ) command_unit.write ( '# gnuplot < ' + command_filename + '\n' ) command_unit.write ( '#\n' ) command_unit.write ( 'set term png\n' ) command_unit.write ( 'set output "' + header + '_plot.png"\n' ) command_unit.write ( 'set xlabel "Distance Rho"\n' ) command_unit.write ( 'set ylabel "Correlation C(Rho)"\n' ) command_unit.write ( 'set title "' + title + '"\n' ) command_unit.write ( 'set grid\n' ) command_unit.write ( 'set timestamp\n' ) command_unit.write ( 'set style data lines\n' ) command_unit.write ( 'plot "' + data_filename + \ '" using 1:2 lw 3 linecolor rgb "blue"\n' ) command_unit.write ( 'quit\n' ) command_unit.close ( ) print ( ' Created command file "' + command_filename + '"' ) return def timestamp ( ): #*****************************************************************************80 # ## timestamp() prints the date as a timestamp. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 August 2019 # # Author: # # John Burkardt # import time t = time.time ( ) print ( time.ctime ( t ) ) return if ( __name__ == '__main__' ): timestamp ( ) damped_sine_plot ( ) timestamp ( )