-
Notifications
You must be signed in to change notification settings - Fork 0
/
gauss.c
56 lines (38 loc) · 1.14 KB
/
gauss.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "gauss_christoffel.h"
int main(){
int NN = 1000;
double sigma2 = 2;
double x0 = 0;
double x[NN+1], w[NN+1];
double psum = 0.;
for(int k=0; k<=NN; k++){
x[k] = 5.*((double)k/NN - 0.5);
w[k] = exp(-(x[k]-x0)*(x[k]-x0)/2./sigma2)/sqrt(2*M_PI*sigma2);
}
FILE *F;
F = fopen("gauss_sample_1000.txt","w+");
for(int k=0; k<=NN; k++)
fprintf(F, "%f\t%f\n", x[k], w[k]);
fclose(F);
int dim = 5;
double nodes[dim], weights[dim];
gauss_christoffel(NN+1, w, x, 1., dim, nodes, weights);
F = fopen("gauss_downsample_N5.txt","w+");
for(int k=0; k<dim; k++)
fprintf(F, "%f\t%f\n", nodes[k], weights[k]);
fclose(F);
dim = 30;
double nodes2[dim], weights2[dim];
gauss_christoffel(NN+1, w, x, 1., dim, nodes2, weights2);
F = fopen("gauss_downsample_N100.txt","w+");
for(int k=0; k<dim; k++){
fprintf(F, "%f\t%f\n", nodes2[k], weights2[k]);
psum += weights2[k];
}
printf("\n check total weight of 30 node sampling: %f\n", psum);
fclose(F);
return 0;
}