Skip to content

Small error in "One Dimensional MC Integration" #438

@domitry

Description

@domitry

$$ I = \int_{0}^{2} x^2 dx $$

While the interval of integration is [0, 2], corresponding sample code is as below:

int N = 1000000;
double sum;
for (int i = 0; i < N; i++) {
auto x = random_double(0,2);
sum += x*x;
}
std::cout << std::fixed << std::setprecision(12);
std::cout << "I = " << sum/N << '\n';

Should sum/N be replaced to 2*sum/N?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions