The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# Questions tagged [numerical-methods]

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

167 questions
Filter by
Sorted by
Tagged with
2k 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: ...
976 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 ...
57 views

### Arbitrary precision Euler-Mascheroni constant via a Brent-McMillan algorithm with no math module

Utilizing the below relation, I am able to compute the Euler constant to great precision on a single thread quickly and simply. My process is to compute the natural log via the AGM(utilizing Pi an ...
41 views

### Euler-Mascheroni Single Thread Speed Improvements

The below code was written to generate γ, for educational purposes. My general methodology is as follows: Compute Gamma via the accepted answer's algorithm here. In order to do this I need to ...
64 views

### Calculate the Euler-Mascheroni constant without the math module

The below code was written to generate γ, for educational purposes. Single threaded, no functional zeroes required, no binary splitting(which can all be used to compute competitively like y-cruncher, ...
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 ...
62 views

### Trapezoidal rule for set of data

Here is the question from the book of Mark Newman-Computational Physics Exc 5.1 a) Read in the data and, using the trapezoidal rule, calculate from them the approximate distance traveled by the ...
51 views

### Evaluating π using Monte Carlo methods - Serial vs OMP

I wrote this simple code for evaluating the π using Monte Carlo method. This is the serial version: ...
55 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 ...
131 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 ...
69 views

### Numerical integration in cython

I have a set of nested functions that I need to call multiple times. I know scipy.quad is pretty fast, but I will need to call the integrator recursively and want ...
139 views

### Simple function that simulates survey results based on sample size and probability

What is this: This is a simple function, part of a basic Monte Carlo simulation. It takes sample size and probability as parameters. It returns the simulation result (positive answers) plus the input ...
85 views

### Calculating pi via collisions

This code calculates pi via collisions; it asks for a user input of N which determines the mass of the second block. It is fully working, it just takes forever to run when N >= 2. I want to be able ...
46 views

### Monte Carlo pi animation

I have created a program that calculates pi using a Monte Carlo method. It also animates the process and displays the value as it is updated to show how it gets closer and closer to the actual value ...
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 ...
109 views

### Java Pi Calculation using an Averaged-Leibniz formula

While trying to discover a way to calculate the digits of Pi faster with the Leibniz formula for Pi, I noticed that, if I took two consecuent numbers in the series, and calculate their average, I ...
568 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 ...
2k views

...
41 views

### A simple clusterness measure of data in one dimension using Java

Problem definition Given $X = (x_1, \dots, x_n)$ such that $x_1 \leq x_2 \leq \dots \leq x_n$. Let $x_{\min} = \min X = x_1$, $x_{\max} = \max X = x_n$ and $r = x_{\max} - x_{\min}$. Also, ...
81 views

### Polynomial implementation in Golang

I am writing a numerical analysis library in golang for which I need to implement a polynomial struct. Here is the source code: ...
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" ...
126 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....
109 views

3k views

### Numeric double integration

I've made a simple program for numerically aproximating double integral, which accepts that the bounds of the inner integral are functions: ...
403 views

### Quasi-Random Number Generators

I would like to communicate a piece of code which I hope will soon be broadly useful for everyone who programs in C++: A set of quasi-random number generators proposed for addition to boost.random. To ...
2k views

### Numerical Differentiation by Finite Differences

Numerical differentiation is known to be ill-conditioned unless using a Chebyshev series, but this requires global information about the function and a priori knowledge of a compact domain on which ...
206 views

### Numerical differentiation on sphere with Python

I have ported from Fortran to Python an algorithm that calculates the numerical derivative along the x direction (longitudinal) of a scalar function s on a ...
529 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 ...
223 views

### Computing the improper integral of several functions

How can I optimize and make prettier the following code? Main.cpp ...
74 views

### Newton's algorithm for a polynomial of arbitary degree

Improvement over the last one I posted (now deleted, had no answers and was only cubics). Uses Horner's algorithm this time... ...