# Questions tagged [numerical-methods]

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

161 questions
Filter by
Sorted by
Tagged with
8answers
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)$. ...
6answers
24k 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 ...
9answers
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. ...
2answers
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 ...
3answers
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 ...
2answers
1k 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" ...
3answers
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 ...
1answer
186 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 ...
6answers
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. ...
2answers
2k views

...
2answers
4k views

### Sqrt (square root) function

As an exercise in learning Scala, I implemented a square root function like this: ...
0answers
50 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 ...
3answers
115 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 ...
1answer
888 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 ...
5answers
967 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 ...
1answer
500 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 ...
1answer
115 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....
1answer
962 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 ...
4answers
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 ...
3answers
848 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 ...
3answers
514 views

### Multithreaded Monte-Carlo Integration

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 ...
1answer
173 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: ...
1answer
815 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 ...
3answers
725 views

1answer
195 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 ...
1answer
235 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, ...
1answer
100 views

2answers
535 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, ...
1answer
70 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 ...
1answer
251 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 ...
1answer
254 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 ...
1answer
2k 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....
2answers
733 views

### Implementation of alternating direction implicit method

I have written a program that implements the ADI method and Crank-Nicolson method for solving Schrodinger equations. The program is working, but it takes a very long time to run. I am looking for ...
1answer
443 views

### C++ HyperLogLog Implementation

I'm a scientific C programmer moving my way over to using Modern C++. I found myself needing a HyperLogLog implementation, and I wanted to use this for practice. I plan to move a number of these ...
2answers
7k views

### Newton's method to solve cubic equations

I have used the Newton-Raphson method to solve Cubic equations of the form $$ax^3+bx^2+cx+d=0$$ by first iteratively finding one solution, and then reducing the polynomial to a quadratic a1*x^2+b1*x+...
1answer
333 views

### Calculating pi to 7 significant figures without using Math.PI

I need to calculate pi to 7 significant figures in Java—without using Math.PI. Here is the code I came up with to do that: ...
1answer
214 views

### Computing the improper integral of several functions

How can I optimize and make prettier the following code? Main.cpp ...
1answer
341 views

### Double exponential quadrature

I'm trying to lighten the code review load for the maintainers of boost.math, and I was hoping you guys could help me out. I have a pull request which implements tanh-sinh quadrature, which is ...
2answers
345 views

### Runge-Kutta 4th order using Python numexpr.evaluate()

I am implementing an ODE solver, where the user provides rates and coefficients as a string. ODE solver has to work with vectors. The best implementation I got so far is the following: ...