Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [numerical-methods]

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

Filter by
Sorted by
Tagged with
6
votes
1answer
361 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: ...
6
votes
1answer
224 views

Computing the improper integral of several functions

How can I optimize and make prettier the following code? Main.cpp ...
6
votes
1answer
351 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 ...
6
votes
2answers
348 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: ...
6
votes
1answer
330 views

Arbitrary Precision nth Principal Root in Java - MathCore #1

This post is the first in the MathCore series. The next post is here: Arbitrary precision π (Circular Constant) in Java - MathCore #2 Disclaimer My project is too big to be reviewed in a single ...
6
votes
0answers
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 ...
5
votes
4answers
823 views

Monte Carlo estimation of π

My C program uses the Monte Carlo method to approximate the mathematical constant π, the ratio of a circle's circumference to its diameter (and, importantly for this code, 4 times the ratio of a ...
5
votes
2answers
26k views

Trapezoidal rule to approximate the integral of x^2

I've implemented the trapezoidal rule to compute the integral for a function \$x^2\$. I would like to see another style of the same code. It seems Matlab hates for a matrix to be expanded without ...
5
votes
3answers
954 views

Bisection to find roots in C++

I have written a short C/C++ code finding root by bisection. (This is a simple iterative numerical method allowing to find the root of an equation i.e. x such that f(x) = 0). Bisection Method The ...
5
votes
2answers
423 views

Monte Carlo simulation of amoeba population

I wrote a simple Python simulation to answer the "Amoeba" population question posed here: A population of amoebas starts with 1. After 1 period that amoeba can divide into 1, 2, 3, or 0 (it can die)...
5
votes
2answers
92 views

Calculating Maclaurin series for sin(x)

I'm very new to Haskell as was hoping to get some feedback on my code AND I have some specific questions. I've posted code below or you can see it here. I'd welcome ideas on how better to calculate ...
5
votes
3answers
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: ...
5
votes
1answer
2k views

Evaluating a series of Legendre polynomials

The following function represents the electrostatic potential, in spherical coordinates, due to a ring of charge \$q=1\$ and radius \$R=1\$, placed in the plane \$x\$-\$y\$: $$\phi(r,\theta) = \sum_{...
5
votes
1answer
384 views

Newton's Method Polynomial solver in Ruby

I am learning Ruby programming from "Learn Ruby the Hard way" and I am doing the "Ruby koans". I have heard a little bit about "Idiomatic" Ruby but I don't know much about it. How can I make it more ...
5
votes
1answer
2k views

Simple neural-network simulation in C++

The C++ code below simulates the timecourse of the membrane potential (V) of a population of 128 leaky integrate-and-fire ...
5
votes
1answer
392 views

Terry Feagin's 10th order explicit Runge-Kutta method

The following Julia code implements Terry Feagin's 10th order explicit Runge-Kutta method (a more accurate cousin of RK4). Though the structure of the code is quite simple (i.e. no cyclomatic ...
5
votes
1answer
114 views

Approximating Pi with Polygons

I wrote a program that approximates Pi by using polygons. I used the formulars in the picture beyond. In my code they are called innerPoly (\$c_{2n}\$) and ...
5
votes
1answer
376 views

Generate dictionary of points on n-sphere

This is a long-shot, but my question is to simply optimize this particular function in some code I have written: ...
5
votes
1answer
4k views

Fixed point iteration and cobweb plot

I'm using Python to find fixed points of a given function and then draw a cobweb plot to visualize it. Thanks to this question, I have the core of the code written and can accomplish the task, but I ...
5
votes
1answer
183 views

Compute PI in Kotlin on a T-shirt

I have written code in Kotlin with the objective of computing Pi in few enough lines so that it looks good on a t-shirt. Can be cut and paste into http://try.kotlinlang.org under "My Programs" and ...
5
votes
2answers
305 views

Python numerical integration

Could the time complexity of this definite integral algorithm be improved? ...
5
votes
1answer
967 views

AVX assembly for fast atan2 approximation

I'm writing a fast atan2 approximation, and would like some feedback on my assembly in particular. I know one of the first things is that people will question why I'm using inline assembly instead of ...
5
votes
1answer
1k views

Computing exponential function by Taylor Series without overflow

The original question is to write a Fortran program to compute the sum of the first 20 terms in the exponential equation (for x=1,2,3,4,5): $$\sum_{n=0}^\infty \frac{x^n}{n!} = 1 + \frac{x^1}{1!} + \...
5
votes
1answer
244 views

Verilog implementation of trapezoidal integration method

Any and all comments are welcome in this review. Problem I've been doing a lot with numerical integration methods recently and have mostly been programming in Python. But...speedups! And FPGAs are ...
5
votes
2answers
990 views

Runge-Kutta fourth order integration

I have written a simple code for Runge-Kutta fourth order integration to solve a system of ordinary differential equations and parallelized it using OpenMP. I don't know if it is the best we can do ...
5
votes
1answer
1k views

Poker Odds Calculation with Monte Carlo

I have created an Odds Calculator in Java. The program gives me the odds, but I want to make sure that they are correct. Maybe someone can tell me a calculator I can compare my results with or knows ...
5
votes
0answers
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 ...
4
votes
2answers
155 views

Computing the double Integral using MonteCarlo techniques using Julia

I decided to try and learn Julia for doing scientific computing, and I decided to tackle the problem of finding $$ \int_{D_{\frac{1}{4}}} x^4 + y^2 dA $$ where \$ D_{\frac{1}{4}} \$ is the part of ...
4
votes
2answers
643 views

Calculating pi by adding areas of thin rectangles

I wrote a small program for fun to try to prove Pi by taking a certain precision and radius and using it to calculate the area of the circle. My method should be giving me an area that is just ...
4
votes
1answer
66 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, ...
4
votes
2answers
4k views

Square Root Calculator

I have now written a simple square root calculator using the division method: ...
4
votes
2answers
2k views

Recursive calculation of second order derivative

I am writing code to do some numerical task using the routines of the book Numerical Recipes. One of my objectives is to calculate the second derivative of a function and have a routine that ...
4
votes
1answer
507 views

Hodgkin-Huxley model in C++

I'm fairly new to C++ and I want to simulate the Hodgkin-Huxley neuron model with it. I have used a MATLAB implementation before and I hope that the C++ code will be faster. Both seem to take the ...
4
votes
2answers
671 views

Runge Kutta ODE Solver

An ordinary differential equation (ODE) is an equation of the kind $$u'(x)=f(t,u(x)).$$ My program attempts to solve such ODE's numerically through explicit Runge Kutta methods. Instead of writing a ...
4
votes
1answer
232 views

Simple neural-network simulation in C++ (Round 3)

As I mentioned at the end of my Round 2 answer, I've needed to expand my code in order to produce faithfully the data needed for Figure 1 of this paper. Unfortunately, the updates have made my script ...
4
votes
2answers
610 views

Discrete random number generator in Python

Description: I am given a list of possible values, each of which have an associated probability of occurrence. How could I improve the algorithm that randomly generates a value based on the given ...
4
votes
2answers
3k views

Implementation of exp function in C using Taylor Series expansion

I am trying to write code to calcultate ex using: $$e^x = \sum_{n=0}^\infty \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \cdots $$ This is the code I have, which works ...
4
votes
2answers
155 views

`atof` revisited

In an answer to this question I mentioned best effort. Here I try to explain what I meant. Please keep in mind that the implementation is intentionally incomplete (missing features such as ...
4
votes
1answer
869 views

Gees - GPL Euler equation solver

As a little helper I recently had to write a code that solves the 1-D Euler equations. As it serves my purpose well I though others could make use of it as well. The homepage of the code can be found ...
4
votes
1answer
94 views

Complex Newton's Method

I'm trying to build a complex Newton's method. I've submitted a PR here, where you can see the documentation and tests, as well as get a compiling example. I'd appreciate y'alls help reducing the ...
4
votes
1answer
3k views

Compute Gini Coefficient

Recently, I was given a math assignment to calculate Gini Indexes for a table of percent distributions of aggregate income. The table takes the form of: ...
4
votes
1answer
624 views

Linear shooting method to solve a B.V.P

I have wrote a code to approximate the solution of a boundary value problem: x'' = p(t)x'(t)+q(t)x(t)+r(t) x(b) = beta in [a,b] by using Runge-Kutta method ...
4
votes
1answer
198 views

Simple neural-network simulation in C++ (Round 4)

You may want to take a look at Rounds 1, 2, and 3, though that isn't necessary for understanding what's below. The major change since Round 3 is that my code is much cleaner and I'm including ...
4
votes
1answer
91 views

How can I make this Euler/RK4 implementation more elegant?

One of the things that I'm doing to teach myself is converting some numerical methods from existing Python code (they seem to me to lend themselves to functional programming quite well). I'd like to ...
4
votes
1answer
301 views

Computing an approximate value of Pi via Monte Carlo method in Java with streams

I have this short program that attempts to compute an approximate value of \$\pi\$: ...
4
votes
1answer
2k views

Calculate the arclength

I am trying to estimate a good approximation for the arclength of the curve \$ y = \sqrt{1-x^2}\$ for \$x \in [0, 1]\$. I did this using a Bezièr curve, and made it so that the area under the two ...
4
votes
1answer
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: ...
4
votes
1answer
219 views

Simple neural-network simulation in C++ (Round 2)

Intro Yesterday I posted this question. Since then, I've updated my code to incorporate these suggestions. I've also removed the dependence on C++11. Finally, I've made the following changes that ...
4
votes
0answers
71 views

Bisection and Newton's method for finding a root of an equation

In an attempt to learn Rust, I've written up implementations of the bisection method and Newton's method for finding roots of an equation. Both methods come in two variants: the first one searches for ...
4
votes
0answers
216 views

Numerical integration with Numba

I'm a bit new to working with Numba, but I got the gist of it. I wonder if there any more advanced tricks to make four nested for loops even faster that what I have ...