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
14
votes
4answers
1k views

Numerical integration in C++: Newton-Cotes formulas

I have tried my hand with implementing simple quadrature formulas in C++. Definite integral: $$\int_a^b f(x) dx$$ Domain of integration \$[a, b]\$ divided into \$n\$ intervals of equal length \$h = (b ...
3
votes
1answer
43 views

libsvm++ : Rewritten libsvm in newer C++

The most famous library for Support Vector Machine (SVM) algorithm is libsvm (https://github.com/cjlin1/libsvm/), but I felt that its code style is too old, I rewrote in newer C++ as a hobby project. ...
4
votes
2answers
335 views

C++: Linear Regression and Polynomial Regression

I wrote a simple linear/polynomial regressor based on my previous matrix project (https://github.com/frozenca/Ndim-Matrix). ...
2
votes
1answer
51 views

Generating a matrix with each row having normalized weights

I just asked this question over Stack Over Flow on how to improve my code and reposting it here as someone on Stack Overflow recommended this platform. I have written two python functions and they are ...
0
votes
0answers
66 views

2D Discrete Fourier Transform using Fortran

I am solving the 2D Wave Equation using Fourier Transform. The Discrete Fourier Transform (and the inverse also) is done inside the kx-loop and ...
3
votes
1answer
91 views

Implementation of Multidimensional numerical integration in C++ and R

I'm trying to perform a 4-dimensional numerical integration in R using a function I wrote in C++ code which is then sourced in <...
4
votes
2answers
194 views

Two dimensional bicubic interpolation implementation in C

This is a follow-up question for Two dimensional bicubic interpolation implementation in Matlab and Two dimensional gaussian image generator in C. Besides the Matlab version code, I am attempting to ...
0
votes
0answers
47 views

Two dimensional bicubic interpolation implementation for dlarray in Matlab

This is a follow-up question for Two dimensional bicubic interpolation implementation in Matlab. While I am working on neural network designing, I want to compare the effects between using padding and ...
2
votes
0answers
224 views

Two dimensional bicubic interpolation implementation in Matlab

I am attempting to implement two dimensional bicubic interpolation algorithm in Matlab. The input is a two dimensional array and the output is the interpolated result. The test input matrix: ...
7
votes
1answer
413 views

Genetic algorithm to guess coefficient of a polynomial

I have tried to code a genetic algorithm to guess the coefficients of a degree 4 polynomial. The information initially provided is values of y = f(x) for different x using the original polynomial. I ...
2
votes
1answer
63 views

A simple clusterness measure of data in one dimension using Java - follow-up 2

(See the previous version here.) This time, I have encorporated all the suggestions made by Marc. Also, I changed the type of points from Double to ...
1
vote
1answer
47 views

A simple clusterness measure of data in one dimension using Java - follow-up

(See the previous version here.) (See the next version here.) This time, I have incorporated all the suggestions made by Roman; my new version follows. ...
14
votes
1answer
373 views

C++ class to create and evaluate Chebyshev approximations of arbitrary functions

I recently needed to create a function to approximate a complex trigonometric function on an embedded system without a floating point unit and without a fast trigonometric library. So I pulled out my ...
5
votes
3answers
145 views

Optimizing an implementation of the RKF method

This is an algorithm regarding the RKF method: ...
1
vote
1answer
55 views

generating stochastic coloured noise for many oscillators

I have a system of n oscillators which oscillate with time. To each of these oscillators I am adding a fluctuating coloured noise term with a different seed for each oscillator. Here is my code for ...
1
vote
0answers
90 views

A Bspline module for AMO

Here is a (reduced version of) a module for Bsplines, which I have used multiple times for my work on Atomic, Molecular, and Optical physics (AMO, in the trade lingo, a.k.a. "I love", in ...
5
votes
1answer
215 views

Using Euler-Maruyama method to solve Ornstein-Uhlenbeck equation (SDE)

I am trying to implement the Euler–Maruyama method and use it to solve the Ornstein–Uhlenbeck process. I am basing my code on the wikipedia page where a python implementation is shown. More generally ...
4
votes
1answer
214 views

Bounded spigot algorithms for e and pi in Python

I've written bounded spigot algorithms(Spigot Algorithm) for e and pi. I would like to understand if there is anything I can do to make this more efficient. I've done things already like move the ...
2
votes
1answer
40 views

Vectorized type conversion for autocorrelation

I have a simple task as part of a larger autocorrelation DSP system - to convert from signed 16-bit integer audio samples to floating-point. This part is quite self-contained: ...
4
votes
1answer
153 views

Modelling of partcle flow under electric field

This is my first modeling exercise on the particle flow. Recently, I read a paper https://acp.copernicus.org/articles/20/3181/2020/. After reading the paper, thought of modeling it in Python. It seems ...
5
votes
1answer
180 views

C++ - Logistic Regression Backpropagation with Gradient Descent

I implemented binary logistic regression for a single datapoint trained with the backpropagation algorithm to calculate derivatives for a gradient descent optimizer. I am primarily looking for ...
4
votes
0answers
81 views

Integrator 2.0: A Simple Integrator in C++17

This is a follow up of A simple definite integrator class of a single variable in C++ I took most of the advice from the user: emma-x and some from user: sudo-rm-rf-slash Here is my fully revised ...
4
votes
2answers
596 views

A simple definite integrator class of a single variable in C++

I have written a simple Integrator class in C++17 that can perform either a definite single integration of a single variable or a definite double integration of a ...
3
votes
2answers
312 views

Implementing a Steepest Descent Algorithm

I am teaching myself some coding, and as my first "big" project I tried implementing a Steepest Descent algorithm to minimize the Rosenbrock function: $$f(x, y) = 100 (y - x^2)^2 + (1 - x)^2$$ The ...
3
votes
1answer
109 views

Linear Interpolation for sorted arrays

I have made a linear interpolation functions as a side project of mine. It assumes everything is sorted before hand - x and f(x) are the same length. I would like to ask for: general recommendations ...
3
votes
2answers
50 views

Newton Raphson and polynomials in C

I have the following code, that defines: A polynomial struct with some useful functions. The newton Raphson algorithm for polynomials. and calculates sqrt(2). ...
1
vote
0answers
72 views

Numerical Double Integration using numba and scipy

Please see the following code. I am using it to calculate the double integration. Please help me to improve the code. ...
7
votes
3answers
3k views

pure Python Bézier curve implementation

I came up with this recursive pure-Python implementation of De Casteljau's algorithm for computing points on a Bézier curve: ...
3
votes
4answers
424 views

Simpson's method for numerically computing the integration of a function

I have implemented the Simpson's rule for numerical integration. Check this video for the implemented function. ...
1
vote
1answer
49 views

What would be the computationally faster way to implement this 2D numerical integration?

I am interested in doing a 2D numerical integration. Right now I am using the scipy.integrate.dblquad but it is very slow. Please see the code below. My need is to ...
1
vote
2answers
71 views

Implementation of Newton's method of finding root of a function

The following is an implementation of Newton's method of finding root of a function. ...
1
vote
2answers
102 views

Simple definite integral calculator

I made this code to compute definite integrals in Processing. It works by getting the rectangle between the maximum value between the previous function value and the current function value, and then I ...
4
votes
1answer
93 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 ...
1
vote
2answers
163 views

Get the best rational approximations for any real number in builtin Python

Best rational approximations is a technical term and not subjective. The best rational approximations are the convergents of a value plus it's semi convergents that are closer to the original value ...
4
votes
0answers
76 views

Estimate area of cropped circle with Monte Carlo

I looking around and not finding anything, I developed a simple function for estimating the area of a possibly cropped circle inside a frame. It uses a very basic MC implementation. It is pretty fast ...
24
votes
4answers
3k 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: ...
13
votes
2answers
1k 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 ...
2
votes
1answer
88 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 ...
1
vote
1answer
57 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 ...
4
votes
1answer
384 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, ...
12
votes
3answers
5k 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 ...
4
votes
2answers
801 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 ...
4
votes
1answer
305 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: ...
13
votes
1answer
119 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 ...
7
votes
1answer
299 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 ...
7
votes
0answers
220 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 ...
7
votes
2answers
144 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 ...
3
votes
1answer
115 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
1answer
69 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 ...
6
votes
1answer
117 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 ...

1
2 3 4 5