Created
April 24, 2021 13:58
-
-
Save harieamjari/786339929d066c9d334273f0e5cf443d to your computer and use it in GitHub Desktop.
Integration of a normal distribution from 0 to +inf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <stdint.h> | |
static double derivative(double x){ | |
return pow(M_E, -pow(x, 2.0)/2.0)/sqrt(2.0*M_PI);} | |
int main(int argc, char **argv) { | |
assert(argc==2); | |
long double delta_t = 0.0000001, u = 0, t = 0; | |
#pragma omp parallel for reduction (+:u,t) | |
for (uint64_t i = 0; i < (uint64_t)((long double)(atof(argv[1])+delta_t)/(long double)delta_t);i++){ | |
t+=delta_t; | |
long double s = (long double)(i+(uint64_t)1)*delta_t; | |
u+=delta_t*derivative(s);; | |
} | |
printf("%0.13Lf %0.13Lf\n", t, u); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment