-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry1.cpp
More file actions
42 lines (35 loc) · 1.12 KB
/
Copy pathtry1.cpp
File metadata and controls
42 lines (35 loc) · 1.12 KB
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
#include <iostream>
#include <math.h>
#include <time.h>
int main() {
srand(time(NULL));
int count = 10; //number of samples
int size = 500; //number of x points
double resolution = 0.1; //distance between x points
double result = 0; //helper value temporarily holds result
double samples[count]; //random points
double x[size]; //result array
// pick random samples
for (int i=0; i<count; i++) {
samples[i] = (double)rand()/RAND_MAX*size*resolution;
//std::cout << samples[i] << "s ";
}
//fill results with 0s
for (int i=0; i<size; i++) {
x[i] = 0;
}
//calculate partial sum for every sample
for (int i = 0; i<count; i++) { //for every sample
for(int j=0; j<size; j++) { // for every x point
if(abs(samples[i] - j*resolution) < 1) {
x[j] += 0.75*(1-pow(samples[i] - j*resolution,2));
}
}
}
for (int i=0; i<size; i++) {
x[i] /= count;
std::cout << x[i] << std::endl;
}
std::cout << std::endl;
return 0;
}