File indexing completed on 2024-04-28 03:48:13
0001 #include <fstream> 0002 #include <iostream> 0003 #include <math.h> 0004 #include <string> 0005 0006 #include <gsl/gsl_randist.h> 0007 #include <gsl/gsl_rng.h> 0008 0009 int main() { 0010 std::string fileName = "out_1M_5pathes.txt"; 0011 int count = 1000000; 0012 int pathes = 5; 0013 0014 double delta = 0.25; 0015 int dt = 1; 0016 double sigma = std::pow(delta, 2) * dt; 0017 double path[pathes] = {0.0}; 0018 0019 std::ofstream ostrm(fileName, std::ios::out); 0020 0021 // header 0022 ostrm << 't'; 0023 for (int p = 0; p < pathes; ++p) 0024 ostrm << "\tx" << std::to_string(p + 1); 0025 0026 ostrm << '\n'; 0027 0028 // create a generator chosen by the environment variable GSL_RNG_TYPE 0029 gsl_rng_env_setup(); 0030 const gsl_rng_type* T = gsl_rng_default; 0031 gsl_rng* r = gsl_rng_alloc(T); 0032 gsl_rng_set(r, 12345); 0033 0034 // data 0035 for (int i = 0; i < count; ++i) { 0036 ostrm << std::to_string(i * dt); 0037 0038 for (int p = 0; p < pathes; ++p) { 0039 path[p] += gsl_ran_gaussian(r, sigma); 0040 ostrm << '\t' << std::to_string(path[p]); 0041 } 0042 ostrm << '\n'; 0043 } 0044 }