Public
Edited
May 14, 2024
Paused
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
f = (x) => {
return 4*Math.sqrt(1-x**2)
}
Insert cell
histoDifferentIterFixed = {
const iterations = [10, 100, 1000, 10000, 100000, 1000000];
const results = [];
return iterations.map((iter) => {
let result = integral(iter);
result["iterations"] = iter;
return result
})
}
Insert cell
histoDifferentIter = {
const results = [];
for (let i=100; i<maxIterations; i+=100) {
let result = integral(i);
result["iterations"] = i;
results.push(result)
}
return results
}
Insert cell
histoSameIter = {
const results = [];
for (let i=0; i<histoSamples; i++) {
results.push(integral(iterations))
}
return results
}
Insert cell
integral = (maxIter) => {
reload;
const pointsOutside = [];
const pointsInside = [];
const yRange = 4;
for (let i =0; i< maxIter; i++) {
const randPointX = Math.random();
const randPointY = Math.random()*yRange;
if (f(randPointX) >= randPointY) {
pointsInside.push({
x: randPointX,
y:randPointY
})
} else pointsOutside.push({
x: randPointX,
y: randPointY
})
}
return {
integral: pointsInside.length/maxIter*yRange,
pointsInside: pointsInside,
pointsOutside: pointsOutside
}
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more