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
4
votes
0answers
231 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 ...
4
votes
0answers
107 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} &=&...
3
votes
2answers
2k 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 ...
3
votes
3answers
77 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... ...
3
votes
3answers
109 views

A collection of vector functionals

I would like some feedback for a collection of what I call "vector functionals", by which I mean maps \$\ell\colon \mathbb{K}^{n} \to \mathbb{K}\$, where the field \$\mathbb{K} = \mathbb{R}\$ or \$\...
3
votes
1answer
142 views

Area under curve

The following code is a solution to a Hackerrank problem in Haskell. Given a list of polynomial coeficients a and exponents b, ...
3
votes
4answers
1k 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 (...
3
votes
2answers
164 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
2answers
2k 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 ...
3
votes
2answers
259 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
87 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 ...
3
votes
2answers
289 views

SICP - exercise 1.7 better end test for square root approximation

Here is exercise 1.7 from SICP: Exercise 1.7 The good-enough? test used in computing square roots will not be very effective for finding the square roots ...
3
votes
2answers
278 views

Spectrum Analysis with Discrete Fourier Transform

Here is a simple implementation of the Discrete Fourier Transform: myFourierTransform.m ...
3
votes
4answers
732 views

Calculating the Riemann Zeta Function for x>2 real numbers

Here's the code: ...
3
votes
1answer
92 views

Golden Section Search in Lisp

I implemented the golden section search algorithm recursively in Lisp. My code is: ...
3
votes
1answer
439 views

Comparing multiple arguments and returns the smallest argument

I want to see if anyone knows how to optimize the code below: ...
3
votes
1answer
760 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 ...
3
votes
2answers
429 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 ...
3
votes
1answer
47 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 ...
3
votes
1answer
78 views

A single function for implementing Newton forward and backward polynomial interpolation

On various websites, I've come across a lot of realizations of Newton polynomial interpolation that use separate functions for forward and backward interpolation, respectively. Such solutions seem ...
3
votes
1answer
73 views

Area under curve and its volume as solid of revolution

I would like to know if there is some more "elegant" way to write these 3 functions. Any tip or idea is welcome. ...
3
votes
2answers
937 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 ...
3
votes
1answer
162 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 ...
3
votes
3answers
3k views

Approximating sines and cosines using up to five terms of the Taylor series

I have one programming question: The sine and cosine of \$x\$ can be computed as follows: \$\sin(x) = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} - \dots\$ ...
3
votes
2answers
2k 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
2k 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
37 views

Fortran 90 / openmp heat transfer simulation optimization

I'm a newbie playing around with Fortran 90 and openmp and wrote the code below (a simple 2D heat transfer simulation) for testing purposes. So far I don't see any speedup by using openmp / parallel ...
3
votes
1answer
91 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: ...
3
votes
1answer
382 views

Monte Carlo Simulation of P-Value

I'm testing Python 3 code to perform a Monte Carlo simulation based on the result of an statistical test. I currently have the result of the statistical test in a pandas dataframe, like this. ...
3
votes
0answers
425 views

Complex multiplication and integration with CUDA

I want to perform multiplication on two vectors and integrate it in a vector called acc_y. The acc_y variable will update over ...
3
votes
0answers
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 ...
3
votes
0answers
126 views

Simple finite difference employing Maccormack technique

I am relatively new to programming and while I am fairly comfortable with the math, I cannot say with confidence that I feel the same way with programming. Anyway here is a simple finite difference ...
3
votes
0answers
65 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 ...
2
votes
2answers
1k 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
2answers
76 views

Approximation of error-function erf(x)

The code beyond approximates the error-function erf(x) with following formular \$erf(x)=1-(a_1t+a_2t^2+a_3t^3)e^{-x^2})\$ for \$x\geq0\$ inclusive the identity \$...
2
votes
1answer
284 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)$$ ...
2
votes
3answers
97 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
145 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 ...
2
votes
1answer
3k views

Polynomial curve-fitting over a large 3D data set

I have a list of 4 images, called listfile.list, which looks like this: image1 image2 image3 image4 Each image has 10 frames containing a 2000 x 2000 array of ...
2
votes
1answer
4k views

ODE45 solver implementation in Python

I have a project where I need ODE solver without dependencies to libraries like Scipy. I decide to implement ODE45. According to tutorials from internet and from what I remember from classes I ...
2
votes
1answer
344 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 ...
2
votes
1answer
96 views

Integer square root

This essentially performs the same function as exact-integer-sqrt in math.numeric-tower. ...
2
votes
1answer
428 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 ...
2
votes
1answer
1k 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 a ...
2
votes
1answer
59 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 ...
2
votes
1answer
52 views

Integral implemented using a trapezoidal Riemann sum

I tried to make this a general purpose integral function but I want to know if it's efficient and idiomatic Rust. ...
2
votes
1answer
491 views

Estimating Pi with random darts on dartboard - high complexity issues

I've been trying to write nice snippet of code to simulate pi estimation by randomly throwing darts on a dartboard. While running the following code on high but reasonable numbers my mac doesn't plot. ...
2
votes
1answer
2k views

Multivariable Gradient Descent in Numpy

Just recently started learning ML, first I've gone through the notes of Ng's Coursera stuff. While I have nothing against Octave, I'm trying to solve exercises in Python. It's my beginning with that ...
2
votes
1answer
187 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
1answer
64 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? ...