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
2 votes
0 answers
63 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
51 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
966 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
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\...
user2373145's user avatar
2 votes
2 answers
76 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
100 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
83 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
  • 197
3 votes
1 answer
169 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
  • 151
0 votes
0 answers
124 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
143 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
217 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
416 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
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: ...
ale victor's user avatar
0 votes
1 answer
46 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
97 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
61 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
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 ...
AlexBatch's user avatar
2 votes
1 answer
123 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,058
0 votes
0 answers
171 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
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 ...
michalt's user avatar
  • 21
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 ...
theWrongAlice's user avatar
1 vote
0 answers
97 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,058
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
97 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
171 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
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?
ght007's user avatar
  • 95
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 (\...
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
564 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
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 ...
Beni Bogosel's user avatar
  • 1,077
1 vote
0 answers
263 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
533 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
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
148 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
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 ...
Balfar's user avatar
  • 63
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) = +\...
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
68 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
198 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,058
0 votes
1 answer
357 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
428 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
144 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
416 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
206 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

1
2 3 4 5