Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
5 votes
1 answer
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 ...
abcd's user avatar
  • 329
4 votes
1 answer
258 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 ...
abcd's user avatar
  • 329
8 votes
3 answers
303 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 Emma X and some from sudo rm -rf slash. Here is my fully revised code: Integrator....
Francis Cugler's user avatar
4 votes
3 answers
2k 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 ...
JimmyHu's user avatar
  • 5,018
1 vote
1 answer
53 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. ...
coderodde's user avatar
  • 28.4k
47 votes
8 answers
10k views

Prettify math formula in code

I have a function to calculate the normal distribution in Python: ...
alvas's user avatar
  • 705
14 votes
4 answers
2k 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 ...
Giogre's user avatar
  • 331
14 votes
1 answer
1k 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 ...
Edward's user avatar
  • 66.4k
10 votes
1 answer
1k views

Generate iCalendar .ics files with events for astrological aspects

I'm relatively new to Python, coming from a deep C++ background. I'm mostly looking for feedback on how to make my code more idiomatic/pythonic, but I would welcome and appreciate any and all other ...
feuGene's user avatar
  • 363
7 votes
3 answers
6k 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: ...
das-g's user avatar
  • 179
6 votes
1 answer
1k 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 ...
auden's user avatar
  • 421
5 votes
2 answers
981 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 ...
Azrael3000's user avatar
5 votes
0 answers
1k 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: ...
JimmyHu's user avatar
  • 5,018
5 votes
1 answer
227 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 ...
physics's user avatar
  • 115
5 votes
2 answers
2k 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 ...
Francis Cugler's user avatar
4 votes
1 answer
666 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, ...
FodderOverflow's user avatar
4 votes
1 answer
387 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 ...
abcd's user avatar
  • 329
4 votes
1 answer
283 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 ...
abcd's user avatar
  • 329
3 votes
4 answers
2k 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 (...
coderodde's user avatar
  • 28.4k
3 votes
2 answers
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 ...
jaresty's user avatar
  • 2,243
2 votes
2 answers
398 views

Implementing multidimensional integral for a custom function in C++

I am not an expert with C++, but I am trying to implement a 4-dimensional integral using GSL numerical integration approach. The code below shows the whole algorithm. Although it seems correct what I ...
CafféSospeso's user avatar
2 votes
1 answer
69 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 ...
coderodde's user avatar
  • 28.4k
2 votes
1 answer
749 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 ...
sator.arepo.tenet.opera.rotas's user avatar
1 vote
1 answer
84 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 ...
FodderOverflow's user avatar
1 vote
1 answer
97 views

A simple clusterness measure of data in one dimension using Java

(See the next follow-up here.) Problem definition Given \$X = (x_1, \dots, x_n)\$ such that \$x_1 \leq x_2 \leq \dots \leq x_n \$. Let \$x_{\min} = \min X = x_1\$, \$x_{\max} = \max X = x_n\$ and \$r =...
coderodde's user avatar
  • 28.4k