Skip to main content

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
1 vote
0 answers
44 views

On reproducing the Poincare section figure in a paper by Sato, Akiyama and Doyne Farmer

This is a repost of a question I posted on MathOverflow, but was suggested to post here due to relevance. I am trying to reproduce Figure 1 in the paper "Chaos in learning a simple two-person ...
Kshitij Kulkarni's user avatar
0 votes
0 answers
50 views

handling symbolical and numerical nested integrals

I'm working on reproducing a calculation from this paper https://arxiv.org/abs/1712.03972 for my thesis but I'm struggling with how to properly implement the nested integrals in Python, specifically ...
Schiele's user avatar
  • 101
1 vote
0 answers
78 views

Numerical integration over part of a sphere

I want to numerically compute the surface integral, $$ \int_0^{2\pi} d\phi \int_{\theta_0}^{\theta_1} d\theta \sin{\theta} f(\theta,\phi) $$ Is there a clever transformation from this integral over ...
vibe's user avatar
  • 1,078
3 votes
0 answers
60 views

Quadrature on an interval $[0,h]$ for $f\in C^3$ vanishing at zero

Cross-posted at Math SE I am studying for an exam and I would like to receive feedback on my solution to a past problem on numerical integration and/or receive suggestions about how to improve my ...
Diffusion's user avatar
  • 131
0 votes
1 answer
84 views

Projecting the initial state on a Discontinuous Galerkin basis

Context I want to solve a 1D Burgers equation with a discontinuous Galerkin approach on the space-time domain $(x,t)\in [0,1]^2$. I want to project the function $u(x) = e^{-\frac{(x-0.5)^2}{0.02}}$ ...
L Maxime's user avatar
3 votes
0 answers
146 views

Quantifying the inefficiency of Gauss–Hermite quadrature

I am trying to understand the following part of the paper https://doi.org/10.1137/20M1389522 where the author argues about the inefficiency of Gauss-Hermite quadrature. I think I get the gist of the ...
Loik's user avatar
  • 31
2 votes
0 answers
73 views

Understanding proof of the error bound for Simpson's quadrature rule

I have found the following proof of the error bound for Simpson's quadrature rule: Using Newton's interpolation method, we derive a cubic polynomial $p_3(x)$ that interpolates $f(x)$ at the points $a, ...
codeing_monkey's user avatar
0 votes
1 answer
80 views

solve_ivp method=ODE23 time step not decreasing in order

My time step with the function scipy.integrate.solve_ivp is not decreasing in t_span fluctuating (reaching values below or ...
louis gouders's user avatar
6 votes
2 answers
1k views

Implementation of Monte-Carlo Integration

After reading the Wikipedia page for Monte-Carlo integration, I have understood the basic idea but I am having trouble implementing it for a general case. The integration that I am trying to do is $$ \...
Michael's user avatar
  • 71
2 votes
0 answers
100 views

Calculating Debye functions to high accuracy (hundreds of bits), is it possible to be faster than generic quadrature?

The Debye functions are defined like so: ${D_n\left(x\right)} = {\frac{n}{x^n} \cdot {\int_0^x{\frac{t^n}{e^t - 1}dt}}}$. I'm trying to evaluate the functions for $n$ from one to four and for $\left\...
user2373145's user avatar
2 votes
2 answers
88 views

How to improve and stabilize this code simulating a damped mass-spring oscillator? Runge-Kutta?

I wrote the following function which is simulating a damped mass-spring oscillator. It is being driven by the audio sample input at 44.1 kHz sampling to create the same effect as a resonant bandpass ...
mikejm's user avatar
  • 123
0 votes
0 answers
117 views

How to minimize a numerical integration in python?

I need some help to minimize a numerical integration. It's about a classical problem in physics (hydrogen atom). It can be solved analytically but I need to solve it numerically in Python. We have an ...
Rubens Filho's user avatar
0 votes
2 answers
2k views

When can I use finite differences for differentiation?

Finite differences are usually used to integrate ODE's and PDE's. However, sometimes they can be used for differentiation which I illustrated simply by using the Matlab code below to differentiate the ...
FriendlyNeighborhoodEngineer's user avatar
0 votes
1 answer
152 views

How to use a custom OdeSolver in Scipy's solve_ivp

In Scipy's solve_ivp documentation, we see the method argument can be either a string or a user-defined ...
Axel Wang's user avatar
  • 307
4 votes
1 answer
179 views

Optimal quadrature rule for heavy tail measure

I'm looking for a well-thought quadrature rule for this measure $d\mu(t)=\frac{dt}{t^s}$ for $s\in(0,1)$, the underlying motivation is to compute this integral $$ \lambda^{s-1}=\frac{1}{\Gamma(1-s)}\...
Aner's user avatar
  • 191
0 votes
0 answers
136 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
1k 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
211 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
417 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
555 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
41 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
48 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
102 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
71 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
65 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
167 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,088
0 votes
0 answers
224 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
64 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
144 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
99 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,078
5 votes
1 answer
1k 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
115 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
216 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
88 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
49 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
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
1k 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
634 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
48 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,077
1 vote
0 answers
331 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
676 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 ...
tanasr's user avatar
  • 3
1 vote
0 answers
42 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
159 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
2k 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
30 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
54 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
444 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
73 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
73 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

1
2 3 4 5