# Questions tagged [numerical-methods]

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

160 questions
Filter by
Sorted by
Tagged with
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)$. ...
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 ...
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. ...
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 ...
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" ...
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 ...
185 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: ...
47 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 ...
114 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 ...
867 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 ...
959 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 ...
495 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 ...
114 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....
948 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 ...
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 ...
839 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 ...
509 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 ...
787 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 ...
155 views

### Root finding and integration

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: ...
654 views

194 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 ...
225 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, ...
2k views

### Linear Interpolation C++

I have to write a collection of methods for performing linear, bilinear and trilinear interpolation. I have also to write some tests to show that interpolation is exact for polynomials (which should ...
3k 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 ...
93 views

### Parallel Ramanujan's formula for 1/π calculation

I finished my university project for calculating $1/\pi$ and I would love to get some feedback. Before you guys jump into this code please keep in mind newcomer to C++ just decided to use it for ...
143 views

### Computing max t such that tanh(pi*sinh(t)/2) <1

I'm looking for a way to quickly determine that maximum value of t such that tanh(pi/2 sinh(t)) is strictly less than 1, for a ...
91 views

### Metropolis Monte Carlo Sampler in Rust

the following is an implementation of the standard Metropolis Hastings Monte Carlo sampler. You can read more about it here. At the end I am going to give you a link to the Rust playground, so you ...
2k views

325 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: ...
213 views

### Computing the improper integral of several functions

How can I optimize and make prettier the following code? Main.cpp ...
330 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 ...
341 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: ...