# include # include # include # include # include # include using namespace std; # include "brownian_motion_simulation.hpp" int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // brownian_motion_simulation_test() tests brownian_motion_simulation(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 11 February 2020 // // Author: // // John Burkardt // { double d; double *dsq; string header; int k; int m; int n; int seed; double t; double *x; timestamp ( ); cout << "\n"; cout << "BROWNIAN_MOTION_SIMULATION_TEST():\n"; cout << " C++ version\n"; cout << " 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 ) { header = "motion_1d"; } else if ( m == 2 ) { header = "motion_2d"; } brownian_motion_display ( m, n, x, header ); delete [] 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 ) { header = "displacement_1d"; } else if ( m == 2 ) { header = "displacement_2d"; } else if ( m == 3 ) { header = "displacement_3d"; } brownian_displacement_display ( k, n, m, d, t, dsq, header ); delete [] dsq; } /* Terminate. */ cout << "\n"; cout << "BROWNIAN_MOTION_SIMULATION_TEST():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // 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: // // 08 July 2009 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }