Questions tagged [integration]

For questions related to integration on computers. This can include numerical approximations of integrals (e.g. Monte Carlo, quadrature, FEM, RK4) and algorithms/software to obtain analytical derivatives (Risch algorithm, SymPy).

Filter by
Sorted by
Tagged with
0 votes
0 answers
72 views

Am I doing leapfrog integration correctly?

I wrote this minimal example to examine the Leapfrog integration algorithm. However, I am not sure it is the correct algorithm, and the listing is giving the correct output. Is this the Leapfrog ...
user366312's user avatar
2 votes
2 answers
870 views

Understanding leapfrog integration algorithm

The leapfrog.cpp is an implementation of leapfrog integration algorithm where f() function is being integrated: leapfrog.cpp <...
user366312's user avatar
0 votes
0 answers
54 views

Solving system of ODEs, where time derivative approaches infinity due top initial condition

I am trying to solve a problem in python using scipy's solve_ivp. The system of ODEs I am trying to solve is for coupled where I am solving for two time-dependent ...
HWIK's user avatar
  • 23
2 votes
1 answer
52 views

2D integrals in Python with specified points of interest

Note: This is my first question on stackexchange; please tell me if I'm doing something incorrectly. I am trying to calculate a series of a 2D integrals in Python with an integrand that has several ...
Feathers's user avatar
2 votes
2 answers
170 views

Solving IVP backward in time via python

I'm having difficulty solving an initial value problem (IVP) in Python backwards in time. The code is at the end of this post. First, please let me state my simplified problem. The forward IVP is ...
JesseJC's user avatar
  • 21
0 votes
0 answers
21 views

Matching the limits of integration with the proper variables in a complicated case when using scipy.integrate.nquad

I need to integrate expressions containing powers of the function: ...
ale victor's user avatar
0 votes
1 answer
37 views

'Integral2' error in MATLAB for invalid integrand

Here is the code that I am trying to run: ...
vidyarthi's user avatar
  • 111
2 votes
2 answers
88 views

How do I evaluate the numerical solution at a point that isn't on the mesh

I'm trying to code a fixed-point method to solve the following system using scipy.integrate $$ u_{n+1}(s)=\int_0^TK_\lambda(t,s)\left(\lambda u_n(t)+\sigma(t)+f(t, ...
tareqath's user avatar
0 votes
2 answers
42 views

How to program the convergence of a sequence of systems of integral equations using Scipy

I'm trying to solve the problem where $u_n$ and $v_n$ are sequences that converge to the solution $u$ and $v$ and $\lambda$, $\sigma$, $f$ and $g$ and K_lambda are all given. I thought of using the ...
tareqath's user avatar
0 votes
1 answer
56 views

Reverse engineering phase shift and numerical damping

I've been trying to validate the physics behind a particle system framework, but I'm having some difficulties. A particle system is a set of lumped masses connected by spring-damper elements. Linear ...
AlexBatch's user avatar
2 votes
1 answer
100 views

Need help to fully understand SciPy's odeint's reported step sizes, eval times, # of funct calls & total proc. time (re. question in Astronomy SE)

A recent question in Astronomy SE Numerical Programming using odeint takes more than 17 minutes got me interested in looking closer at SciPy's odeint. The problem is a modified orbital mechanical ...
uhoh's user avatar
  • 1,016
0 votes
0 answers
97 views

Numerical integration library interfacing with eigen

I am looking for a numerical integration library like this one. The examples look very appealing but I see that all test functions use very barebones C arrays. Do you have any recommendations of ...
KeynesCoeFen's user avatar
2 votes
0 answers
60 views

Symplectic (or alike) integrator for system with Coulomb singularity and time-dependent potentials

I am trying to calculate classical trajectories for a single positive ion and a single electron inside an RF trap. Therefore, I am dealing with a two-body system that possesses: Coulomb potential ...
michalt's user avatar
  • 21
1 vote
0 answers
84 views

Convolution/weighted average of two arrays in Python

I have an equation that I need to calculate numerically, but I am having doubts about my approach. I am cross-posting this question from Stack Exchange, because I am not getting any responses. This is ...
theWrongAlice's user avatar
1 vote
0 answers
92 views

Integration problem

I want to numerically solve integrals of the form, $$ I = \int_a^b x^k f(x) dx $$ where $k$ is a given integer, and $f(x)$ is a cubic polynomial, expressed as, $$ f(x) = c_0 + c_1 (x - a) + \frac{c_2}{...
vibe's user avatar
  • 1,038
5 votes
1 answer
755 views

Why is velocity Verlet better than Verlet for gravity if it has a worse order of magnitude for the error term

Even though this method is more widely used than the simple Verlet method mentioned above, it unfortunately has an error term of O(Δt^2) , which is two orders of magnitude worse. That said, if you ...
ght007's user avatar
  • 95
0 votes
1 answer
66 views

Integration of a singular kernel function over a triangle

Problem: I am currently trying to integrate a singular kernel function of the type $$G(x,y)=\frac{\exp(ik||x-y||_2)}{4\pi ||x-y||_2}$$ which lies at the centre of a triangle, over this triangle. $i$ ...
Bulbasaur's user avatar
  • 101
0 votes
0 answers
116 views

discrete definition of curl $ \nabla \times \vec{A}$ on a 3D grid?

I have the data for 3D vector field $\vec{A}$ (with components $\vec{A_1}$, $\vec{A_2}$ and $\vec{A_3}$) sampled on a 3D grid with integer indices i, j and k. Assuming that only the third component $\...
rockonkl's user avatar
1 vote
0 answers
67 views

Why can we remove the half-step velocity in velocity Verlet

Eliminating the half-step velocity, this algorithm may be shortend to Why can we eliminate the half-step velocity and all the math behind the velocity Verlet to what Wikipedia shows?
ght007's user avatar
  • 95
0 votes
0 answers
41 views

Numerical Method for Multivariate Inversion Formula

For my research, I need to evaluate the density of a random vector $\boldsymbol{X} \in \mathbb{R}^p$ using the multivariate inversion formula. Let the density function of $\boldsymbol{X}$ be $f (\...
little_sky's user avatar
0 votes
0 answers
43 views

B-spline abscissa values for numerical stability

I am working with spline functions using the B-spline basis, $$ f(x) = \sum_{i=1}^n c_i B_i(x;\mathbf{t}) $$ where the $B_i$ are cubic B-splines with a knot vector $\mathbf{t}$. For my application, ...
vibe's user avatar
  • 1,038
4 votes
3 answers
1k views

How can I numerically integrate the Kepler problem?

I tried to solve a simple Kepler problem numerically. I have discrete time steps, a starting position $(x_0,y_0)$ and starting velocity $(u_0, v_0)$. I used this iteration by calculating the forces ...
MichaelW's user avatar
  • 151
8 votes
2 answers
2k views

Energy conservation in RK4 integration scheme in C++

My colleague and I are trying to study the three-body problem, with different integration schemes, starting from the two-body problem. We implemented the symplectic Euler scheme and the Runge–Kutta ...
jack23456's user avatar
  • 171
3 votes
1 answer
537 views

Using the Kramers-Kronig (Hilbert) transform in Python

I am trying to use the Kramers-Kronig algorithm to transform the real and imaginary contributions to the anomalous scattering factor from a diffraction anomalous fine structure (DAFS) experiment. I ...
ayrton burgess's user avatar
1 vote
1 answer
336 views

RK4 integration of the three-bodies problem with C++

first of all thank you for all the answers you gave me yesterday for the integration via Symplectic Euler's method of the three-body problem. We managed to implement both Euler's and Runge Kutta 4's ...
jack23456's user avatar
  • 171
0 votes
0 answers
39 views

Quadrature rules for products of 2D regions

I am interested in computing integrals of the form $\iint_{P\times P} Q(x_1,x_2,y_2,y_2) dxdy$ where $P$ is a polygon and $Q$ is a polynomial. The coordinates $(x_1,x_2)$ are in the plane of $P$. Of ...
Beni Bogosel's user avatar
1 vote
0 answers
141 views

Monte Carlo simulation for the quantum oscillator in the path integral approach

The theory Consider a quantum harmonic oscillator described by the potential $V(q)=\frac{1}{2}m\omega^2 x^2$. In the path integral formulation, the partition function can be written as $$Z\propto\int ...
My Code is a Flying Circus's user avatar
0 votes
1 answer
245 views

Passing additional arguments to `odeint` from `torchdiffeq` to solve an IVP

In Python I use the package torchdiffeq (as provided here) to solve initial value problems. Given an arbitrary function ...
eldorado's user avatar
1 vote
0 answers
41 views

Integral from function approximations

I have some data which I cannot manage to model and fit with a known function, so let’s say that they are a sample from the unknow function $f(x)$, which look a sort of skewed bell-shaped distribution....
Stefano Barone's user avatar
1 vote
1 answer
120 views

Integration of (d-1)-dimensional functions on finite element surfaces

I am trying to integrate a function $\hat u$ on the common surface of discontinuous finite elements. The function $\hat u$ lives in a $d-1$-dimensional space of functions defined on the element ...
Wil's user avatar
  • 63
3 votes
2 answers
997 views

Inaccurate results of integration using scipy solve_ivp

I am trying to use solve_ivp to solve the following 1st order ODE: $$ \frac{d \rho}{d z} = \frac{m \theta}{(1+\theta z)} \, \rho, $$ subject to $\rho(z=0)=1$, where ...
Fryderyk's user avatar
0 votes
0 answers
26 views

What are the known or used numerical methods for integration over the sphere $S^2$ ? and what about over $S^3$?

What are the numerical methods available to compute integrals over $S^2$, for the particular integration : $$\int_{S^2} f(\omega)\,d\sigma(\omega)\ , \quad \text{ where $d\sigma$ is the usual measure ...
NotaChoice's user avatar
1 vote
0 answers
45 views

Numerical integration of a 2D hemisphere discrete dataset where limits are unknown

I am trying to compute the integral of a 2D hemisphere dataset $f_r \, (\theta, \phi)$ where $\theta \in [0, \pi / 2[$ and $\phi \in [0, 2\pi]$. I am making the measurements myself, so I can choose ...
Balfar's user avatar
  • 63
1 vote
1 answer
380 views

Integral of the Poisson Kernel

I am trying to solve the following integral: $$ I (r,\theta) = \frac{1}{2\pi}\int_0^{2\pi}\frac{f(\phi)(1-r^2)}{1+r^2-2r \cos(\theta-\phi)}d\phi$$ where $0\le r<1$ and, $$f(0\le\phi<\pi/2) = +\...
Babaji's user avatar
  • 195
1 vote
1 answer
71 views

Integration in 3D

So the question was to use a nested loop to solve a 3D integral with the function conditions (written below in the code) to find $$\int dxdydz $$ and the x and y coordinate of the centre of mass of ...
Phy's user avatar
  • 13
2 votes
0 answers
60 views

How to implement a generic monte carlo algorithm for n-dimensional integration?

A very visual picture for Monte Carlo integration is the approximation of $\pi$, by sampling in a square which contains a quarter of the unit circle. We can extend this picture to 3 dimensions, by ...
infinitezero's user avatar
2 votes
1 answer
178 views

Quadrature of rational functions

I have a class of integrals I need to solve numerically which have the form: $$ I_k = \int_a^b \frac{p_k(x)}{x^k} dx, \quad k = 0, 1, \dots, K $$ where $p_k(x)$ is a cubic polynomial on the interval $[...
vibe's user avatar
  • 1,038
0 votes
1 answer
285 views

How to deal with solving coupled ODE systems where variables are updated multiple times within each timestep?

I'm solving a system of coupled ODEs using Euler integration for simplicity. To make this concrete, please see the (extremely simplified) minimal working example below in Python. Imagine we have a box ...
quantumflash's user avatar
2 votes
1 answer
302 views

High precision numerical integration of discrete data with Matlab

I have discrete data of a function plotted below: The "Y" values of the function near "X=1.57" are very close to each other and zero, like 9.25558265263186E-11 and 5....
tio's user avatar
  • 23
4 votes
0 answers
122 views

Quadrature rules for non-linear finite element problems

For solving linear problems stemming from PDEs with the FEM, such as the Poisson equation or the wave equation, it is customary to use the "simplest" numerical quadrature that exactly ...
Andreas Longva's user avatar
2 votes
0 answers
252 views

Efficient way of calculating a cumulative integral with prefactor

I have a grid of points $x_i$ and corresponding function values $y_i=f(x_i)$. I'm interesting in something like the cumulant of $f$, but it has an awkward prefactor. The desired quantity we'll call $$...
Root of All Things's user avatar
3 votes
1 answer
182 views

Question about energy in the shallow water equations on a staggered grid

I think this is a question about the energy conservation of a numerical integrator. I'm studying the linearized 1D shallow water equations in python - for reference, here they are: $$ \frac{\partial u}...
theWrongAlice's user avatar
2 votes
0 answers
378 views

Numerical evaluation of Duhamel's integration

I am trying to numerically evaluate the following Duhamel's integration: $$ x = \frac{-1}{\omega_d} \int_0^t \ddot{x}_g (\tau) e^{-\zeta \omega_n(t - \tau)} \sin{\left( \omega_d (t - \tau) \right)} d\...
Quang Thinh Ha's user avatar
6 votes
3 answers
262 views

Numerical integration giving incorrect sign

For my research, I need to integrate the following function: $$ W(z)=\int_0^{\infty}dx\ w(x,z)\\ =\int_0^{\infty}dx\frac{e^x}{(e^x+1)^2}\log{\left(\frac{e^{z^2/4x+x}+1}{e^{z^2/4x+x}-e^x}\right)}\\ =\...
surrutiaquir's user avatar
0 votes
0 answers
72 views

Fourier integral over elements

Suppose I have a triangular element with vertices ${\vec{r_1},...,\vec{r_3}}$ and a function $f(\vec{r})$. I want to calculate the fourier integral over this triangle such that: $$F(k_x,k_y)=\int \int ...
strahd's user avatar
  • 11
3 votes
1 answer
265 views

Importance Sampling for multidimensional integrals and random numbers from multivariable pdf's

I am aiming to get a numerical value for a five-dimensional integral using Monte Carlo Integration. I am getting good results using the Mean Value Method, but I would like to try to use Importance ...
pollux33's user avatar
6 votes
0 answers
96 views

What is the best method to do a MC Integration of a multidimensional integral where the integration limits depend upon other variables?

What is the best method to do a Monte Carlo Integration of a multidimensional integral where the integration limits depend upon other variables? I am interested in getting a numerical value of a 5 ...
pollux33's user avatar
1 vote
1 answer
349 views

Compute 2D numerical double integration with Boost C++ with parameters

I am trying to compute the double Richardson and Wolf integrals for the focusing of a lens with Boost in C++ (using the Gauss Kronrod method). As a starting point, I used the example presented in this ...
Bertrand Simon's user avatar
4 votes
0 answers
91 views

Sample Average Approximation vs. Numerical Integration

To calculate the expected value of objective functions, we have two choices: Sample Average Approximation (SAA): $$ \frac{1}{N}\sum_{i=1}^N f(x,\xi^i). $$ Numerical Integration (e.g., Monte Carlo ...
Keith's user avatar
  • 41
2 votes
1 answer
4k views

Error in Simpson's 3/8 rule is higher than that of Simpson's 1/3 rule

For a given function $f(x)$, I have tried to find its numerical integral using Simpson's 1/3 and Simpson's 3/8 rules. I then compare the solution from the numerical quadratures to the analytical ...
justauser's user avatar
  • 145

1
2 3 4 5