Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [numerical-methods]

Algorithms which solve mathematical problems by means of numerical approximation (as opposed to symbolic computation).

8
votes
0answers
65 views

Discrete Lanczos Derivatives

I have a PR implementing denoising discrete Lanczos derivatives, following this paper. The following code works well, but the design is a train wreck, and I was hoping to get some advice to improve it....
3
votes
3answers
102 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 \$\...
4
votes
1answer
64 views

Complex Newton's Method

I'm trying to build a complex Newton's method. I've submitted a PR here, where you can see the documentation and tests, as well as get a compiling example. I'd appreciate y'alls help reducing the ...
1
vote
0answers
35 views

Solving heat equation using forward finite differences [closed]

I am trying to improve a procedure that uses explicit forward finite differences for solving the heat equation. It is typically the scheme shown below. (32-bit program Delphi XE10.1) ...
4
votes
0answers
41 views

Bisection and Newton's method for finding a root of an equation

In an attempt to learn Rust, I've written up implementations of the bisection method and Newton's method for finding roots of an equation. Both methods come in two variants: the first one searches for ...
6
votes
0answers
61 views

Metropolis Monte Carlo Sampler in Rust

the following is an implementation of the standard Metropolis Hastings Monte Carlo sampler. You can read more about it here. At the end I am going to give you a link to the Rust playground, so you ...
4
votes
0answers
91 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 ...
5
votes
0answers
69 views

Implementing numerical integration in Python

I have this Python code that implements a rectangular numerical integration. It evaluates the (K-1)-dimensional integral for arbitrary integer \$K \geq 1\$ $$\int_{u_K = 0}^{\gamma}\int_{u_{K-1} = 0}^...
7
votes
3answers
296 views

Implementing numerical integration

I have this C++ code that implements a rectangular numerical integration. It evaluates the \$K\$-dimensional integral $$\int_{u_K = 0}^{\gamma}\int_{u_{K-1} = 0}^{\gamma-u_K}\cdots\int_{u_2}^{\...
5
votes
3answers
643 views

Bisection to find roots in C++

I have written a short C/C++ code finding root by bisection. (This is a simple iterative numerical method allowing to find the root of an equation i.e. x such that f(x) = 0). Bisection Method The ...
7
votes
1answer
90 views

2d linear Partial Differential Equation Solver using finite differences

This is code that solves partial differential equations on a rectangular domain using partial differences. fd_solve takes an equation, a partially filled in output, ...
5
votes
1answer
149 views

Compute PI in Kotlin on a T-shirt

I have written code in Kotlin with the objective of computing Pi in few enough lines so that it looks good on a t-shirt. Can be cut and paste into http://try.kotlinlang.org under "My Programs" and ...
5
votes
2answers
82 views

Calculating Maclaurin series for sin(x)

I'm very new to Haskell as was hoping to get some feedback on my code AND I have some specific questions. I've posted code below or you can see it here. I'd welcome ideas on how better to calculate ...
12
votes
3answers
970 views

Definite Integral Approximation using the Trapezoidal Method

I wrote a program to calculate the value of Definite Integral of a function from a to b. It used the trapezoidal approximation ...
4
votes
0answers
111 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 ...
3
votes
1answer
70 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 ...
5
votes
2answers
3k views

Compute a numerical derivative

Since I could not get numpy.gradient() to compute a derivative successfully, I wrote a script to compute it manually. Running the script below will output a plot of ...
3
votes
0answers
150 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 ...
18
votes
9answers
4k views

Approximating constant π² to within error

This function takes as input float error and approximates constant π² to within error by computing this sum, term by term, until the difference between the new and the previous sum is less than error. ...
1
vote
1answer
74 views

Runge-Kutta Fourth Order in C

I've found that the Runge-Kutta (4th order) calculations in some software I wrote are the bottleneck. Is there anything obvious I can do to improve efficiency here? Note that Compiler optimizations ...
4
votes
1answer
191 views

Computing an approximate value of Pi via Monte Carlo method in Java with streams

I have this short program that attempts to compute an approximate value of \$\pi\$: ...
5
votes
3answers
1k views

Numeric double integration

I've made a simple program for numerically aproximating double integral, which accepts that the bounds of the inner integral are functions: ...
5
votes
0answers
191 views

Quasi-Random Number Generators

I would like to communicate a piece of code which I hope will soon be broadly useful for everyone who programs in C++: A set of quasi-random number generators proposed for addition to boost.random. To ...
3
votes
0answers
665 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 ...
1
vote
0answers
179 views

Numerical differentiation on sphere with Python

I have ported from Fortran to Python an algorithm that calculates the numerical derivative along the x direction (longitudinal) of a scalar function s on a ...
8
votes
3answers
367 views

Multithreaded Monte-Carlo Integration

I have a PR implementing multithreaded naive Monte-Carlo integration here. My requirements for the class are the following: It should support progress reporting, ETA, and graceful cancellation. It ...
6
votes
1answer
168 views

Computing the improper integral of several functions

How can I optimize and make prettier the following code? Main.cpp ...
3
votes
3answers
66 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
2answers
125 views

Spectrum Analysis with Discrete Fourier Transform

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

Finding the root of a function by Bisection Method

The program has to look for a root in an interval [a,b]. The root should be declared with a certain accuracy eps. I.e it should ...
4
votes
1answer
378 views

Hodgkin-Huxley model in C++

I'm fairly new to C++ and I want to simulate the Hodgkin-Huxley neuron model with it. I have used a MATLAB implementation before and I hope that the C++ code will be faster. Both seem to take the ...
1
vote
2answers
310 views

Bisection method solver

I have a simple bisection method solver that I was told it has some problems in design and I need my code to be reviewed, so I was hoping for someone to give me guideline on how to improve my code. ...
2
votes
0answers
236 views

Computing the square root of a number using binary search

This is implemented in MIPS assembly. I've hard-coded the initial guess, as I haven't figured out how to allow the user to input a negative or non-negative integer to then display the result back to ...
4
votes
2answers
487 views

Discrete random number generator in Python

Description: I am given a list of possible values, each of which have an associated probability of occurrence. How could I improve the algorithm that randomly generates a value based on the given ...
5
votes
2answers
242 views

Python numerical integration

Could the time complexity of this definite integral algorithm be improved? ...
3
votes
1answer
70 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. ...
6
votes
1answer
262 views

Calculating pi to 7 significant figures without using Math.PI

I need to calculate pi to 7 significant figures in Java—without using Math.PI. Here is the code I came up with to do that: ...
3
votes
1answer
249 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. ...
5
votes
1answer
612 views

AVX assembly for fast atan2 approximation

I'm writing a fast atan2 approximation, and would like some feedback on my assembly in particular. I know one of the first things is that people will question why I'm using inline assembly instead of ...
3
votes
2answers
189 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 ...
5
votes
2answers
686 views

Runge-Kutta fourth order integration

I have written a simple code for Runge-Kutta fourth order integration to solve a system of ordinary differential equations and parallelized it using OpenMP. I don't know if it is the best we can do ...
6
votes
1answer
1k views

Monte Carlo simulation to approximate the value of PI

This is a C++ implementation of a simple Monte Carlo simulation to approximate the value of pi. The program uses the standard library Mersenne twister engine to generate two random numbers between -1....
12
votes
1answer
160 views

Calculate the closest point to many hyperbolic paraboloids

In this question I asked for a way to compute the closest projected point to a hyperbolic paraboloid using python. Using the iterative approximation answer, I'm able to use the code below to ...
3
votes
1answer
123 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, ...
4
votes
2answers
470 views

Runge Kutta ODE Solver

An ordinary differential equation (ODE) is an equation of the kind $$u'(x)=f(t,u(x)).$$ My program attempts to solve such ODE's numerically through explicit Runge Kutta methods. Instead of writing a ...
2
votes
1answer
2k 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 ...
1
vote
0answers
74 views

Scala Functional Programming ODE Solver

I'm new to both Scala and Functional programming. I've been doing the excellent course Functional Programming Principles in Scala on Coursera and I want to test out what I've learned. I've written a ...
2
votes
1answer
44 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. ...
3
votes
2answers
73 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 \$...
5
votes
1answer
105 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 ...