QVector<QPollarF> BrownianMotion::BrownianMotionSimulation() { double dt; QPollarF dx; int j; double norm_dx; double s; QVector<QPollarF> x(Nts + 1); dt = totaltime / (double) (Nts - 1); x[0].setX(0.0); x[0].setY(0.0); for (j = 1; j < Nts; j++) { s = sqrt(diffusionCoef * dt) * gsl_ran_ugaussian_pdf(rng->randd()); dx = gaussianUniform01(); norm_dx = 0.0; norm_dx = norm_dx + pow(dx.x(), 2); norm_dx = norm_dx + pow(dx.y(), 2); norm_dx = sqrt(norm_dx); dx.setX(s * dx.x() / norm_dx); dx.setY(s * dx.y() / norm_dx); x[j].setX(x[j - 1].x() + dx.x()); x[j].setY(x[j - 1].y() + dx.y()); } return x; }
void test_normal() { gen g_uni[] = {builtin, devurandom, kalkulator, mersenne, #if N <= (1 << 12) randorg, #endif 0}; test t[] = {chisq, kolsmir, 0}; task* prob = task_new(0, g_uni, t, 0 ); gsl_histogram* h = gsl_histogram_alloc(B); gsl_histogram_set_ranges_uniform(h, 0, 1); gsl_histogram_shift(h, AVG); prob->density = h; gsl_histogram2d* hd = gsl_histogram2d_alloc(B2, B2); gsl_histogram2d_set_ranges_uniform(hd, 0, 1, 0, 1); gsl_histogram2d_shift(hd, AVG2/2); prob->density2d = hd; prob->min = 0; prob->max = 1; task_perform(prob); task_free(prob); gen g_gauss[] = {gauss_bm, gauss_zig, gauss_ratio, 0}; prob = task_new(2, g_gauss, t, 0); prob->max = 3; prob->min = -prob->max; h = gsl_histogram_alloc(B); gsl_histogram_set_ranges_uniform(h, prob->min, prob->max); int j; for (j=0; j<B; ++j) { double min, max; gsl_histogram_get_range(h, j, &min, &max); double x = (max + min)/2; gsl_histogram_accumulate(h, x, N*gsl_ran_ugaussian_pdf(x) / B * (prob->max - prob->min)); } hd = gsl_histogram2d_alloc(B2, B2); gsl_histogram2d_set_ranges_uniform(hd, prob->min, prob->max, prob->min, prob->max); int k; for (j=0; j < B2; ++j) for (k=0; k<B2; ++k) { double min, max; gsl_histogram2d_get_xrange(hd, j, &min, &max); double x = (max + min)/2; gsl_histogram2d_get_yrange(hd, k, &min, &max); double y = (max + min)/2; gsl_histogram2d_accumulate(hd, x, y, gsl_ran_ugaussian_pdf(x) * gsl_ran_ugaussian_pdf(y)); } gsl_histogram2d_scale( hd, N/2/gsl_histogram2d_sum(hd) ); prob->density = h; prob->density2d = hd; task_perform(prob); task_free(prob); }
double test_ugaussian_ratio_method_pdf (double x) { return gsl_ran_ugaussian_pdf (x); }
double test_ugaussian_pdf (double x) { return gsl_ran_ugaussian_pdf (x); }
QPollarF BrownianMotion::gaussianUniform01() { return QPollarF(gsl_ran_ugaussian_pdf(rng->randd()), gsl_ran_ugaussian_pdf(rng->randd())); }