Algorithms which solve mathematical problems by means of numerical approximation (as opposed to symbolic computation).
3
votes
1answer
22 views
Multithreaded Monte Carlo pi approximation with own pseudorandom number generator
I made a Monte Carlo pi approximation program, that makes use of multithreading and a pseudorandom number generator I wrote (the one from big_wheel.hpp, which I ...
4
votes
1answer
47 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:
...
3
votes
0answers
38 views
Computing nth roots of a number - SICP exercise 1.45
From SICP
Exercise 1.45:
We saw in 1.3.3 that attempting to compute square roots
by naively finding a fixed point of x/y does not converge, and that
this can be fixed by average damping.
...
3
votes
2answers
100 views
Euler's Method in C#
I was just looking for some feedback for my c# program to run Euler's method. I was just wondering on any possible improvements, refactoring, inefficiencies... the usual stuff you probably deal with ...
1
vote
1answer
47 views
Approximating pi/4 using Wallis Product - SICP exercise 1.31
From SICP
The sum procedure is only the simplest of a vast number of similar
abstractions that can be captured as higher-order procedures. Write an
analagous procedure called product that ...
2
votes
2answers
83 views
Calculating Pi with Android
I'm kind of new to Java but I am writing an Android app. Right now I'm working on an async task to calculate Pi but when I run it the memory usage increases alarmingly (+5MB per second). This one ...
3
votes
1answer
57 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
133 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 ...
5
votes
0answers
135 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 ...
3
votes
3answers
160 views
5
votes
2answers
93 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, ...
2
votes
1answer
64 views
Calculation of elasticity for non-linear curve
I've written this code to calculate the elasticity for econometric analysis. Basically, this algorithm estimate the function:
$$\epsilon(x) = \frac{x}{f(x)}\ f'(x)$$
...
4
votes
1answer
59 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:
...
2
votes
1answer
38 views
Evaluation of e^x with series expansion
My code calculates \$e^x\$ with series expansion. Is there any way to make it shorter and cleaner?
...
5
votes
1answer
139 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_{...
2
votes
1answer
227 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 ...
5
votes
2answers
117 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)...
2
votes
0answers
51 views
Numerical differentiation using the y-intercept
I have a routine for determining the derivative of a function using the y-intercept (B) to infer the finite difference step (h). ...
4
votes
2answers
158 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 ...
5
votes
1answer
124 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:
...
3
votes
2answers
270 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 ...
6
votes
3answers
170 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 ...
4
votes
0answers
311 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 ...
3
votes
1answer
57 views
Square root calculation in Scheme (SICP Exercise 1.7)
I have done exercise 1.7 in SICP (calculate square root precision when change in guesses is under a certain value), but I am calling the change-in-precision function twice in each iteration, which ...
4
votes
2answers
60 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 ...
2
votes
1answer
64 views
Integer square root
This essentially performs the same function as exact-integer-sqrt in math.numeric-tower.
...
3
votes
1answer
62 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 ...
3
votes
1answer
66 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 ...
2
votes
1answer
178 views
Double integral solver in TI-84
Here's a program I made for estimating a double integral over a general region. It's pretty accurate, but it's VERY, VERY slow. (Getting an accurate enough result takes about 30 seconds)
Here's the ...
6
votes
1answer
97 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 ...
3
votes
4answers
290 views
Computing integer square roots in Java - follow-up
(See the previous iteration.)
My two previous methods for computing the integer square root of a number \$N\$ ran in the \$\mathcal{O}(\sqrt{N})\$ worst case time. Now I have added a method (...
6
votes
1answer
217 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 ...
10
votes
3answers
97 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 ...
5
votes
1answer
190 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 ...
3
votes
1answer
122 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 ...
3
votes
1answer
111 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 ...
3
votes
1answer
151 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
1answer
417 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 ...
2
votes
1answer
74 views
Golden Section Search in Lisp
I implemented the golden section search algorithm recursively in Lisp. My code is:
...
3
votes
0answers
61 views
Decorator for setting up bracketing rootfinding functions
I'm looking for comments on the use of decorators for the following problem (validating initial guesses for bracketing rootfinding methods), as well as any other comments you might have on the design ...
3
votes
3answers
1k views
Implementation of Brent's Algorithm to find roots of a polynomial
I made a program that contains a root-finding algorithm for polynomials as a function and contains 3 test polynomials. The algorithm is Brent's method and is based entirely off the pseudocode from ...
2
votes
2answers
138 views
Root-finding by iterated bisection
Both of the following code give the same result. But I'm not sure where should I put the raise statement.
...
2
votes
0answers
26 views
Iterative procedure to get 3D coordinates from distance constraints
Imagine you have a series of n points randomly generated in a box in 3D space. You also have a list of distance bounds, e.g. points 5 and 3 should be between 1.0 and 2.0 Angstroms apart.
There are ...
8
votes
4answers
278 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 ...
7
votes
1answer
125 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 ...
2
votes
3answers
89 views
Calculating e^x by math.h and by own means
For this program, the user needs to enter an exponent and the program will calculate \$e\$ (Euler's number) to the power of the exponent the user inputs.
This is done by two ways:
By the math.h ...
2
votes
1answer
82 views
Utility Method to find the Square root of a number
Utility to calculate the square root of a number. The method also accept an epsilon value, which controls the precision. The epsilon value could range to any number including zero. I am expecting a ...
4
votes
1answer
410 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 ...
1
vote
2answers
162 views
5
votes
1answer
128 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 ...