Skip to content

Instantly share code, notes, and snippets.

@harieamjari
Created April 24, 2021 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harieamjari/786339929d066c9d334273f0e5cf443d to your computer and use it in GitHub Desktop.
Save harieamjari/786339929d066c9d334273f0e5cf443d to your computer and use it in GitHub Desktop.
Integration of a normal distribution from 0 to +inf
#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