Skip to content

Instantly share code, notes, and snippets.

View TwoDollarsEsq's full-sized avatar
🦊

Artyom Rudakov TwoDollarsEsq

🦊
  • Ukraine, Dnipro
  • 15:47 (UTC +02:00)
View GitHub Profile
@TwoDollarsEsq
TwoDollarsEsq / MonteCarloIntegration.swift
Last active May 31, 2019 19:06
In mathematics, Monte Carlo integration is a technique for numerical integration using random numbers. It is a particular Monte Carlo method that numerically computes a definite integral. While other algorithms usually evaluate the integrand at a regular grid, Monte Carlo randomly choose points at which the integrand is evaluated.
import Foundation
extension Double { static var e: Double { return 2.72 } }
let function: Func1D = sqrt
let bounds: Bounds = (0, 4)
// Using compact 1D interfaces
// 1D
mc(in: bounds, f: function, N: 1000)