Skip to content

Monte Carlo

Neil Ghugare edited this page Nov 14, 2025 · 1 revision

Monte Carlo


Table of Contents


About

This code is for Monte Carlo numerical methods.

The code is original but based off of multiple pseudo-algorithms and mathematical formulae.

Copyright © 2025 RandomKiddo


Current Implemented Methods

Area (Definite Integral Approximation):

The naive Monte Carlo approach. Approximating the definite integral

$$I = \int{\Omega} f(\mathbf{x})\ d\mathbf{x},$$

via sub-sampling points uniformly on $\Omega$ $N$-times, such that

$$\mathbf{x}_1,\cdots,\mathbf{x}_N \in \Omega,$$

and we can approximate the integral,

$$I \approx Q(N) \equiv \frac{V}{N} \sum_{i=1}^N f(\mathbf{x}_i),$$

where

$$V = \int_{\Omega} d\mathbf{x}.$$

It can be shown that

$$\lim_{N \rightarrow \infty} Q(N) = I.$$

Importing

Importing the subpackage can be done (if installed through PyPI or equiv.):

from astrocore import montecarlo

or

from astrocore.montecarlo import *

Usage

This subpackage can only be used in Python directly (due to the difficulties of representing matrices in the command line). You can define whatever matrices and variables you need and solve:

from astrocore.montecarlo import area

# Driver code
def f(x: float) -> float:
    return x**3 - x

area(f, 0.0, 1.0)

Back to Top

This page was last edited on 11.14.2025

Clone this wiki locally