# 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).

210 questions
Filter by
Sorted by
Tagged with
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, ... 0 votes 1 answer 48 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 ... 6 votes 2 answers 965 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 $$\... 2 votes 0 answers 98 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\... 2 votes 2 answers 75 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 ... 0 votes 0 answers 97 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 ... 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 ... 0 votes 1 answer 81 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 ... 3 votes 1 answer 168 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)}\... 0 votes 0 answers 123 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 ... 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 <... 0 votes 0 answers 140 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 ... 2 votes 1 answer 209 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 ... 2 votes 2 answers 413 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 ... 0 votes 0 answers 27 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: ... 0 votes 1 answer 46 views ### 'Integral2' error in MATLAB for invalid integrand Here is the code that I am trying to run: ... 2 votes 2 answers 96 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, ... 0 votes 2 answers 60 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 ... 0 votes 1 answer 61 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 ... 2 votes 1 answer 390 views ### Double Integral with Gauss- Hermite for one component I am trying to perform the following integral$$\int_{0}^{2\pi}\int_{0}^{+\infty} \frac{r'\left(e^{-r'^2/2\sigma^2}\right)\left(r-r'\cos(\theta-\theta')\right)}{r^2+r'^2-2rr'\cos(\theta-\theta')}dr'... 2 votes 1 answer 122 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 ... 0 votes 0 answers 170 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 ... 2 votes 0 answers 62 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 ... 1 vote 0 answers 126 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 ... 1 vote 0 answers 96 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}{... 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 ... 0 votes 0 answers 170 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 \... 0 votes 1 answer 96 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 ... 1 vote 0 answers 77 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? 0 votes 0 answers 43 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 (\... 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 ... 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 ... 2 votes 3 answers 304 views ### Calculating the antiderivative numerically In the standard literature topics like numerical differentiation and numerical integration are usually discussed in detail. However, numerical integration is not the same as calculating the (true) ... 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 ... 1 vote 1 answer 558 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 ... 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 ... 0 votes 0 answers 44 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 ... 1 vote 0 answers 260 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 ... 0 votes 1 answer 526 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 ... 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.... 1 vote 1 answer 145 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 ... 11 votes 5 answers 9k views ### Integral in log-log space I'm working with functions which, in general, are much smoother and better behaved in log-log space --- so that's where I perform interpolation/extrapolation, etc, and that works very well. Is there ... 1 vote 0 answers 51 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 ... 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 ... 13 votes 2 answers 8k views ### Which Runge-Kutta method is more accurate: Dormand-Prince or Cash-Karp? I simply want to know whether the Dormand-Prince Numerical Method or the Cash-Karp Numerical Method is more accurate. 3 votes 1 answer 396 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 ... 1 vote 1 answer 420 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) = +\... 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 ... 2 votes 1 answer 197 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$[...
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 ...