Algorithms which solve mathematical problems by means of numerical approximation (as opposed to symbolic computation).
2
votes
0answers
18 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
119 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 ...
6
votes
1answer
53 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
80 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 ...
1
vote
0answers
54 views
Iterated root-finding and optimization
I am quite new to Python and I have trouble finding the roots of a function.
The ultimate goal is to find $$y=(a_1,p_0,\theta)$$ such that they minimize the function $$-\sum\limits_{j=1}^{n} ...
2
votes
1answer
39 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
72 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
62 views
0
votes
0answers
71 views
Stochastic gradient descent in R
Please, review my code, which counts global minimum with method stochastic gradient descent for schaffer function
...
2
votes
0answers
49 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 ...
0
votes
1answer
92 views
Summation for π [closed]
I was going through my Java book's exercise solutions and comparing and incorporating the author's techniques into my repertoire.
Most of the time, my approach is identical to the author's. When it ...
5
votes
1answer
139 views
Iterative equation solver in Python
In order to solve a equation where the left hand side appears under an integral on the right hand side:
$$
B(p^2) = C\int_0^{p^2}f_1\left(B(q^2),q^2\right)\mathrm{d}q^2 + C\int_{p^2}^{\Lambda^2} ...
1
vote
2answers
75 views
Bisection method for finding the root of a function
For those who aren't familiar with the bisection method for finding the root of a function (i.e. finding where \$f(x) = 0\$) the basic idea is:
Take a function \$f(x)\$ and an interval \$[a,b]\$
If ...
3
votes
1answer
45 views
Comparing multiple arguments and returns the smallest argument
I want to see if anyone knows how to optimize the code below:
...
4
votes
2answers
383 views
Square Root Calculator
I have now written a simple square root calculator using the division method:
...
3
votes
0answers
45 views
Volatility updating with Heston-Nandi model
I'm trying to program a volatility updating rule using iteration. I start with the well-known Heston-Nandi model where the returns dynamics are:
$$
\left\{
\begin{array}{rcl}
R_{t+1} ...
2
votes
2answers
91 views
Newton's square root
This is the code I wrote to compute the newton's square root of a number.
I aimed for extreme clarity over efficiency and I have put an abundant docstring at the start of the ...
13
votes
2answers
505 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 ...
3
votes
2answers
99 views
Multifunctional Monty Hall Simulator
Based on this question on math.SE regarding probabilities in variations on the Monty Hall problem, I cobbled up a simulator in Ruby to give myself an introduction to the language.
Since this is my ...
3
votes
1answer
141 views
Percentage based drop prize on Mob entity kill
I have created a simple percentage-based random prize drop for killing certain mobs.
A drop is basically what the player will get in return for killing a mob, as a reward.
So I have a large list of ...
13
votes
6answers
3k 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 ...
8
votes
5answers
616 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 ...
3
votes
2answers
169 views
Hamiltonian Monte Carlo in Scala
I'm writing a program in Scala to perform Hamiltonian Monte Carlo (HMC), coupled with Gibbs sampling of some variables. The algorithm, with the modifications such as perturbing epsilon and l and ...
5
votes
2answers
138 views
Monte Carlo estimation of the Hypergeometric Function
I am trying to implement the algorithm described in the paper Statistical Test for the Comparison of Samples from Mutational Spectra (Adams & Skopek, 1986) DOI: 10.1016/0022-2836(87)90669-3:
$$p ...
4
votes
2answers
5k 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 ...
3
votes
1answer
61 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 ...
5
votes
1answer
888 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 ...
10
votes
6answers
2k 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.
...
6
votes
2answers
3k 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 ...
6
votes
1answer
750 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 ...
3
votes
2answers
498 views
Square root approximations, implemented two ways
Which version is more efficient in calculating the square root ?
There are 2 versions I have written to calculate square root programatically. Note reqs strictly state not using library functions ?
...
3
votes
1answer
720 views
Solving an ODE numerically with forward Euler method
The goal is to solve an ODE numerically with forward Euler method. The programs works well (numerical solution really near analytical one). The problem I see is that the Euler scheme don't jump to ...
3
votes
1answer
617 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 ...
1
vote
1answer
779 views
Integral using Simpson's Rule
As an answer to this problem:
Exercise 1.29
Simpson's Rule is a
more accurate method of numerical
integration than the method
illustrated above. Using Simpson's
Rule, the integral of ...
2
votes
2answers
987 views
Use Newton's Method to compute sqrt(x)
Given the following task:
Use Newton's method to compute the square root of a number. Newton's
method involves successive approximation. You start with a guess, and
then continue averaging ...