# Questions tagged [numerical-methods]

Algorithms which solve mathematical problems by means of numerical approximation (as opposed to symbolic computation).

170 questions
Filter by
Sorted by
Tagged with
7k views

### Prettify math formula in code

I have a function to calculate the normal distribution in Python: ...
8k views

### PI Calculator, Interview Challenge

Greg Beech says here that he asks C# candidates to produce a formula that calculates PI Given that Pi can be estimated using the function $4 * (1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \dots)$. ...
25k views

### Monte Carlo pi calculation

In order to learn the basics of Monte Carlo I calculated pi with it. I also wrote an explanation of the reasoning behind the code. Down here you can see the circle with random points that I simulated ...
3k views

### IEEE 754 square root with Newton-Raphson

I have an implementation of the sqrt function that uses a combination of IEEE 754, packed bitfields, and the Newton-Raphson algorithm: ...
4k views

### Approximating constant π² to within error

This function takes as input float error and approximates constant π² to within error by computing this sum, term by term, until the difference between the new and the previous sum is less than error. ...
2k views

### Simulating a two-body collision problem to find digits of Pi

I came across a nice video on 3Blue1Brown's channel that highlights a very indirect way to find the digits in Pi. I'd suggest watching the whole video, but briefly: The setup is as above. A "small" ...
3k views

### Pi by Monte-Carlo

I was inspired by this SO post to investigate a good Java8 way to calculate Pi based on simulation. I used a similar task to learn about parallel programming on both CUDA, and Intel Xeon Phi ...
986 views

### Mean π: Archimedes vs. Gauss - π computation through generalized means

I've written this simplified code to compute Pi for educational/demonstration purposes. These methods are based upon the generalized means: see a presentation on Pi and the AGM. Archimedes' method ...
81 views

### Continuous Fourier integrals by Ooura's method

I have a PR implementing Ooura and Mori's method for continuous Fourier integrals. I used it here to compute an oscillatory integral that Mathematica got completely wrong, and then I thought "well ...
2k views

### Definite Integral Approximation using the Trapezoidal Method

I wrote a program to calculate the value of Definite Integral of a function from a to b. It used the trapezoidal approximation ...
4k views

### Python π = 1 + (1/2) + (1/3) + (1/4) - (1/5) + (1/6) + (1/7) + (1/8) + (1/9) - (1/10) …1748 Euler

I wrote this code to show that my reddit post is correct. After the first two terms, the signs are determined as follows: If the denominator is a prime of the form 4m − 1, the sign is positive; if ...
196 views

### Calculate the closest point to many hyperbolic paraboloids

In this question I asked for a way to compute the closest projected point to a hyperbolic paraboloid using python. Using the iterative approximation answer, I'm able to use the code below to ...
4k views

### Approximating the square root using an iterative method

I wrote this code, based on the Newton-Raphson method, to find the square root of a number. I'm wondering how I can optimise this code, as I am out of ideas. ...
2k views

...
4k views

### Sqrt (square root) function

As an exercise in learning Scala, I implemented a square root function like this: ...
994 views

### Probabilistic matchmaking simulation

The following is a problem I found on this wiki. What can I do to optimize my algorithm, and make this code more C++11? Write a program to discover the answer to this puzzle:"Let's say men and ...
119 views

### Reinventing the Math Functions

Just for practice in the mathematical side of programming, I decided to rewrite the math functions, with the addition of the root() function, which the Math library ...
998 views

### Generate iCalendar .ics files with events for astrological aspects

I'm relatively new to Python, coming from a deep C++ background. I'm mostly looking for feedback on how to make my code more idiomatic/pythonic, but I would welcome and appreciate any and all other ...
547 views

### Gamma function in Rust

The gamma function is one of a couple nice continuous extensions to the traditional factorial function. I used this Python program as a reference, which in turn, uses this Ada program. As the Ada ...
137 views

### Discrete Lanczos Derivatives

I have a PR implementing denoising discrete Lanczos derivatives, following this paper. The following code works well, but the design is a train wreck, and I was hoping to get some advice to improve it....
1k views

### Approximating Pi, Monte Carlo integration

I wrote some code that uses Monte Carlo Integration to Approximate pi in Java and Akka. The tl;dr explanation is you can imagine throwing darts at a square with a circle inscribed inside of it. You ...
6k views

### Finding the root of a function by Bisection Method

The program has to look for a root in an interval [a,b]. The root should be declared with a certain accuracy eps. I.e it should ...
1k views

### Buffon's Needle experiment

I was working on a program that simulates the Buffon's Needle experiment. If anyone is not familiar with it, a Wiki link is provided - Buffons's Needle The point of Buffon's experiment is to find ...
924 views

### 1D shock tube problem written in Fortran

I have written a simple Euler solver for the 1D shock tube problem. Eventually, I plan to extend this code to solve the full 3D compressible Navier-Stokes equations. Therefore, I want to start with ...
669 views

### Visualizing Newton-Raphson method for finding zeroes of a function

I have created a program to visualize the working of Newton-Raphson method to find the zeroes of a function: newton.m: ...
545 views

I have a PR implementing multithreaded naive Monte-Carlo integration here. My requirements for the class are the following: It should support progress reporting, ETA, and graceful cancellation. It ...
176 views

### Root finding and integration [closed]

I am trying to implement the modified Next Reaction Method with time varying propensities as mentioned in sections IV and V of this paper. At one step in the process this expression must be evaluated: ...
889 views

### Fitting multiple piecewise functions to data and return functions and derivatives as Fortran code

Background For a future workshop I'll have to fit arbitrary functions (independent variable is height z) to data from multiple sources (output of different ...
4k views

### Python class that implements the Newton method

Here is a python function I wrote to implement the Newton method for optimization for the case where you are trying to optimize a function that takes a vector input and gives a scalar output. I use ...
1k views

196 views

### Monte Carlo Pi (MASM)

I'm currently trying to brush up on my assembly skills and, being at the FPU section of the tutorial, I implemented a very basic version of a Monte-Carlo-Algorithm to compute pi. I deliberately use ...
303 views

### 2d linear Partial Differential Equation Solver using finite differences

This is code that solves partial differential equations on a rectangular domain using partial differences. fd_solve takes an equation, a partially filled in output, ...
101 views

625 views

### Monte-Carlo method to estimate Pi runs slower in multiple threads, than in single thread

I'm learning Scala, and I wrote a program to estimate the value of Pi. When I'm using multiple threads, it takes 5-6 times longer to calculate the same iterations. I wrote a similar program in Java, ...
72 views

### Monte Carlo errors estimation routine

I would value your opinion on the following piece of code. I am rather new to both Python and Monte Carlo analysis, so I was wondering whether the routine makes sense to more experienced and ...
277 views

### Approximating π via Monte Carlo simulation

Inspired by a tweet linked to me by a friend and a Haskell implementation by her for the same problem, I decided to try my hand at approximating the value of π using everything in the Haskell standard ...
977 views

### C++ Pi Calculator - Leibniz Formula

Yesterday I saw a CodeTrain video in where Daniel Shiffman tried to approximate Pi using the Leibniz series. It was interesting so I decided to try it too. I wrote this console application with a ...
3k views

### Monte Carlo simulation to approximate the value of PI

This is a C++ implementation of a simple Monte Carlo simulation to approximate the value of pi. The program uses the standard library Mersenne twister engine to generate two random numbers between -1....