# include # include # include # include # include # include "brownian_motion_simulation.h" int main ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: brownian_motion_simulation_test() tests brownian_motion_simulation(). Licensing: This code is distributed under the MIT license. Modified: 01 October 2012 Author: John Burkardt */ { double d; double *dsq; char header[80]; int k; int m; int n; int seed; double t; double *x; timestamp ( ); printf ( "\n" ); printf ( "BROWNIAN_MOTION_SIMULATION_TEST():\n" ); printf ( " C version\n" ); printf ( " Test BROWNIAN_MOTION_SIMULATION().\n" ); /* Compute the path of a particle undergoing Brownian motion. */ for ( m = 1; m <= 2; m++ ) { n = 1001; d = 10.0; t = 1.0; seed = 123456789; x = brownian_motion_simulation ( m, n, d, t, &seed ); if ( m == 1 ) { strcpy ( header, "motion_1d" ); } else if ( m == 2 ) { strcpy ( header, "motion_2d" ); } brownian_motion_display ( m, n, x, header ); free ( x ); } /* Estimate the average displacement of the particle from the origin as a function of time. */ for ( m = 1; m <= 3; m++ ) { k = 40; n = 1001; d = 10.0; t = 1.0; seed = 123456789; dsq = brownian_displacement_simulation ( k, n, m, d, t, &seed ); if ( m == 1 ) { strcpy ( header, "displacement_1d" ); } else if ( m == 2 ) { strcpy ( header, "displacement_2d" ); } else if ( m == 3 ) { strcpy ( header, "displacement_3d" ); } brownian_displacement_display ( k, n, m, d, t, dsq, header ); free ( dsq ); } /* Terminate. */ printf ( "\n" ); printf ( "BROWNIAN_MOTION_SIMULATION_TEST():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: TIMESTAMP prints the current YMDHMS date as a time stamp. Example: 31 May 2001 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 24 September 2003 Author: John Burkardt Parameters: None */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); fprintf ( stdout, "%s\n", time_buffer ); return; # undef TIME_SIZE }