{"id":27040058,"url":"https://github.com/cuadernin/integralsimulation","last_synced_at":"2025-04-05T03:27:41.098Z","repository":{"id":240263931,"uuid":"335830263","full_name":"Cuadernin/IntegralSimulation","owner":"Cuadernin","description":"Computes the value of a definite integral using Monte Carlo simulation.","archived":false,"fork":false,"pushed_at":"2021-06-19T03:57:33.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-17T16:59:19.998Z","etag":null,"topics":["integral","monte-carlo","monte-carlo-simulation","simulation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cuadernin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-04T03:46:14.000Z","updated_at":"2024-05-17T16:59:21.937Z","dependencies_parsed_at":"2024-05-17T16:59:21.751Z","dependency_job_id":"773cd982-99ef-46ec-b784-f20141a8d019","html_url":"https://github.com/Cuadernin/IntegralSimulation","commit_stats":null,"previous_names":["cuadernin/integralsimulation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuadernin%2FIntegralSimulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuadernin%2FIntegralSimulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuadernin%2FIntegralSimulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuadernin%2FIntegralSimulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cuadernin","download_url":"https://codeload.github.com/Cuadernin/IntegralSimulation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284931,"owners_count":20913690,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["integral","monte-carlo","monte-carlo-simulation","simulation"],"created_at":"2025-04-05T03:27:40.534Z","updated_at":"2025-04-05T03:27:41.081Z","avatar_url":"https://github.com/Cuadernin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Integral Simulation\nComputes the value of a definite integral using Monte Carlo simulation in Python.\n## Problem to solve ✔\nIf X is a continuous random variable with density function f\u003csub\u003ex\u003c/sub\u003e and g is a continuous function, the expectation of g(X) is given by:\n\n\u003cimg src=\"https://latex.codecogs.com/png.latex?\\dpi{80}\u0026space;\\bg_white\u0026space;\\LARGE\u0026space;E(g(X))=\\int_{-\\infty\u0026space;}^{\\infty\u0026space;}g(x)f_x(x)dx{\\color{Blue}\u0026space;}\" title=\"\\LARGE E(g(X))=\\int_{-\\infty }^{\\infty }g(x)f_x(x)dx{\\color{Blue} }\" /\u003e\nIf X is uniformly distributed in [0, 1], then\n\n\u003cimg src=\"https://latex.codecogs.com/png.latex?\\dpi{80}\u0026space;\\bg_white\u0026space;\\LARGE\u0026space;E(g(X))=\\int_{0}^{1}g(x)dx\" title=\"\\LARGE E(g(X))=\\int_{0}^{1}g(x)dx\" /\u003e\n\nThis fact suggests that we can use simulation to estimate the previous integral, estimating the value of E(g(X)). If X\u003csub\u003e1\u003c/sub\u003e, X\u003csub\u003e2\u003c/sub\u003e, X\u003csub\u003e3\u003c/sub\u003e, ..., X\u003csub\u003en\u003c/sub\u003e are independent and uniformly distributed in [0, 1], then the g(X\u003csub\u003ei\u003c/sub\u003e) are also independent. \nTherefore, if we define the mean of g(X) as:\n\n\u003cimg src=\"https://latex.codecogs.com/png.latex?\\dpi{80}\u0026space;\\bg_white\u0026space;\\LARGE\u0026space;\\overline{g(x)}=\\frac{g(X_1)\u0026plus;g(X_2)\u0026plus;...\u0026plus;g(X_n)}{n}\" title=\"\\LARGE \\overline{g(x)}=\\frac{g(X_1)+g(X_2)+...+g(X_n)}{n}\" /\u003e\n\nand we assume that g(X) has mean μ and variance σ², then:\n\n\u003cimg src=\"https://latex.codecogs.com/png.latex?\\dpi{80}\u0026space;\\bg_white\u0026space;\\LARGE\u0026space;E(\\overline{g(X)})=\\mu\u0026space;\\phantom{abcd}\u0026space;V(\\overline{g(X)})=\\frac{\\sigma^2}{n}\" title=\"\\LARGE E(\\overline{g(X)})=\\mu \\phantom{abcd} V(\\overline{g(X)})=\\frac{\\sigma^2}{n}\"/\u003e\n\nThese two equalities suggest that to estimate μ, we can generate a sequence of numbers u\u003csub\u003e1\u003c/sub\u003e, u\u003csub\u003e2\u003c/sub\u003e, u\u003csub\u003e3\u003c/sub\u003e, ..., a uniformly distributed in [0, 1], independent and calculate (g(u\u003csub\u003e1\u003c/sub\u003e)+g(u\u003csub\u003e2\u003c/sub\u003e)+g(u\u003csub\u003e3\u003c/sub\u003e)+...+g(u\u003csub\u003en\u003c/sub\u003e))/n.\nNote that the variance of the mean g(X) can be made as small as you like by taking it large enough.\n\n## Input📋\nA menu of options is displayed where you must choose the type of interval where the integral will be calculated, that is:\n* 1 == **[a, b]**\n* 2 == **[0, 00]** \n* 3 == **[-00 , 00]**\n\nNext, you must write the function in terms of x and the limits of the interval.\n\n```\nexp(-x**2)\n```\nIt means\n \u003cimg src=\"https://latex.codecogs.com/png.latex?\\dpi{80}\u0026space;\\bg_white\u0026space;\\LARGE\u0026space;e^{-x^2}\" title=\"\\LARGE e^{-x^2}\" /\u003e\n \n ## Output 📦\n * **Simulated value**\n * **Real value**\n * **Percentage error**\n \n ### Note\n You can do the exact same thing for a multiple integral.\n \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuadernin%2Fintegralsimulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuadernin%2Fintegralsimulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuadernin%2Fintegralsimulation/lists"}