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
1 answer
209 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,078
0 votes
1 answer
377 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
472 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
159 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
518 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
231 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
514 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
287 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
76 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
475 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
105 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
459 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
103 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
6k 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 vote
1 answer
84 views

Definite Numerical Integration with Unknown limit

How to solve for small gamma in the integral equation in Scipy ? I recognize it has to be solved with both the numerical integral and a root solver (Newton's method) $$ \int_{\gamma}^{+\infty}f(x) dx =...
Sam Gomari 's user avatar
1 vote
1 answer
204 views

Does the leap-frog algorithm conserve energy for n-body problems?

The leap-frog algorithm is able to conserve to a certain extent the energy of a system, which flucutates as a cosine around a stable value. Is this true if we apply the algorithm to a n-body ...
Francesco Pettini's user avatar
-1 votes
1 answer
207 views

Solving ODEs, Rotations, Angular Velocity, Euler Angles

I am implementing a simulation that needs to rotate and object based on known angular velocity (assumed constant for simplicity). I followed the ideas given below, pg. 32) https://graphics.stanford....
BBSysDyn's user avatar
  • 239
5 votes
0 answers
557 views

Fast integration scheme for path integral of Gaussian over a cubic curve

I need to numerically compute an integral of the following form: $$\int_0^1 \frac{1}{2\pi\sigma^2}\exp\left(-\frac{\|(q_0t^3 + q_1t^2 + q_2t + q_3) - a\|^2}{2\sigma^2}\right)\|3q_0t^2 + 2q_1t + q_2\|\,...
Phil's user avatar
  • 151
0 votes
2 answers
153 views

Computing infinite series with iterated functions

I found this question (linked here) which asks to find what this infinite series converges to $$ \sum_{n=1}^{\infty} \int_0^{\pi} f_n(x) dx $$ where $f_{n+1}(x) = \sin(f_n(x)) $ and $f_1 = \sin(x)$. ...
Ryan Howe's user avatar
  • 111
2 votes
3 answers
317 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) ...
ConvexHull's user avatar
  • 1,498
0 votes
1 answer
126 views

Free Electron Schrödinger Equation (Energy Method)

For the simplest atom, its wave function is described by the PDE of Schrodinger equation: $$ -i h \frac{\partial u}{\partial t }=\frac{h^{2}}{2m} \Delta u + \frac{e^{2}}{r}u$$ The potential $\frac{e^{...
user avatar
1 vote
1 answer
121 views

Numerical integrator for $a'(t)=e^{-a(t)}f(t)$

Suppose I know a function $f(t)$ and all its derivatives in $t$ in closed form. Given $a(0)$ and some $t_0>0$, I'm looking for an explicit integrator that can estimate $a(t_0)$, where $a(\cdot)$ ...
Justin Solomon's user avatar
5 votes
0 answers
188 views

Why does this integral converge faster than normal rectangle or trapz integration?

I was looking for the fastest converging method to integrate a family of functions. After some tries, an old-school colleague suggested me a method that he used to use in excel to perform such task. ...
Luca's user avatar
  • 151
2 votes
0 answers
736 views

Errors in Integral Estimate of Gaussian using Trapezoidal Rule

I'm trying to estimate the percentage error in computing the integral of a Gaussian via composite trapezoidal rule versus via an exact formula. To do this I've generated a gaussian with mean 0, ...
Cazador's user avatar
  • 21
-1 votes
1 answer
573 views

ODE45 and a variable that assumes multiple values during the timespan

I have tried in different ways to see what happens to voltage V and gating conductances m, n and h when, at time step x, current I switched from 0 to 0.1, and then at time step x + n it gets back to 0....
Sam's user avatar
  • 1
5 votes
2 answers
3k views

CUDA & Python for numerical integration and solving differential equations

Can anyone please suggest some libraries which allow use CUDA in Python for numerical integration and/or solving of differential equations? My goal is to solve large (~1000 equations) of coupled non-...
Artem Alexandrov's user avatar
0 votes
2 answers
226 views

Integrate a function from samples using computer codes

I have a function $c ( I (\vec{r}) )$. Not a constant, $c$ doesn't denote a constant. So $c$ is a function of $I$ which is a function of $\vec{r}$. $I$ is an intensity (W/cm2). This $c$ is hard to ...
velenos14's user avatar
  • 141
2 votes
1 answer
998 views

nquad Integration in SciPy

I am trying to self-learn SciPy and evaluate the following quadruple integral using scipy.integrate.nquad: $$\int_{0}^{1} \int_{0}^{1} \int_{0}^{1} \int_{0}^{1-x} (...
Sha's user avatar
  • 125
1 vote
1 answer
73 views

Gauss Integration of $\sqrt(x)$

I want to construct a gauss integration for the weight function $w(x) = x^{1/2}$ for $$\int_{0}^{1}x^{1/2}f(x)dx = a_{1}f(x_{1})+a_{2}f(x_{2})$$ Solving \begin{align*} a_{1}+a_{2} =& \int_{0}^{...
user avatar
2 votes
1 answer
2k views

Trouble with backwards time integration in Python

I am struggling with a rather basic numerical integration task: Using Python's scipy.integrate.solve_ivp module to integrate an ODE sytem backwards in time. As a test, I am using the following ODE ...
Leonidas's user avatar
  • 163
2 votes
0 answers
158 views

How to derive the adjoint sensitivity equations for a least squares objective function gradient

The Problem I would like to determine the gradient of a least squares objective function which depends on a vector of 40 parameters $p$, and the solution of a system of 32 differential equations. In ...
kostas1335's user avatar
0 votes
0 answers
94 views

Integration of a discretized field in a cylindrical coordinate system

I would like to integrate a discretized field in cylindrical coordinates, given as A(r, z), with z being spaced regularly (...
arc_lupus's user avatar
  • 563
2 votes
1 answer
135 views

Trouble Making 3rd-Order Sympletic Integrator for Planitary N-Body Problem (A Hamiltonian System)

I am doing a solar-system simulation. I am using Ruth's 3rd order sympletic integrator to avoid the problem of Energy Drift (which I had with RK4), but the the planets quickly leave orbit, and energy ...
maxbear123's user avatar
2 votes
1 answer
3k views

Numerical integration problem: IntegrationWarning The integral is probably divergent, or slowly convergent

I am trying to get the numerical integration of a function using scipy's integrate.quad as follows. $$ \begin{equation} G (\alpha) = \frac{4\alpha}{\pi}\int_0^{\...
NoVel's user avatar
  • 23
3 votes
1 answer
475 views

Choosing an appropriate time step for a discrete & continuous dynamics simulation

I have inherited of a flight dynamics simulation in C++ which represents a small drone with it's autopilot, actuator dynamics and a solid state IMU. Hence, it is composed of a few models, some ...
J.M's user avatar
  • 131
3 votes
1 answer
323 views

Find quadrature points and weights

I'm struggling with the following problem: What is the maximum degree of exactness that we can obtain with the following quadrature >formula $$\int_0^1 f(x)\frac{1}{\sqrt{x}}dx \approx w_0 f(x_0) +...
lukk's user avatar
  • 31
0 votes
0 answers
109 views

Nondifferentiable coordinate transforms

Suppose that we have coordinates $u=u(x,y)$ and $v=v(x,y)$ in $\mathbb{R}^2$ so that $v$ is not differentiable when $u(x,y)=u_0$ where $u_0$ is a constant. Can we solve a differential equation, such ...
tohoyn's user avatar
  • 331
4 votes
1 answer
758 views

How to use numerical integration to calculate the surface area of a superellipsoid?

I am working in an application in which I need to calculate the surface area of a superellipsoid. I have read that there is no closed form solution (see here), so I am trying to compute it using ...
llorente's user avatar
1 vote
0 answers
77 views

Computation of a functional for large values

Consider the following function : $$f(x) = \sin^2(\frac{π\Gamma(x)}{2x})$$ Now consider the following functional : $$I(x)=\int_0^\infty \frac{f(x + iy) − f(x − iy)}{e^{2πy}-1} dy$$ I need values for ...
bambi's user avatar
  • 119
2 votes
2 answers
498 views

Weak form of the Navier-Cauchy equation

I am trying to obtain the weak form of the Navier-Cauchy equation, which is $$- \rho \omega ^2 \textbf{U} - \mu \nabla ^2 \textbf{U} - (\mu + \lambda) \nabla (\nabla \cdot \textbf{U}) = \textbf{F}$$ ...
Lucas Vieira's user avatar
1 vote
0 answers
171 views

Is Romberg integration method implemented as weighted function values numerically correct?

I have to integrate expression f(x) * g(x) for many different functions f but just one g. I ...
abukaj's user avatar
  • 123
0 votes
2 answers
265 views

Integration by parts with cross derivatives to obtain the weak form [duplicate]

I’m trying to write the weak form of the Navier-Cauchy equation in the component form, where $u_1$ and $u_2$ are the displacement components: $$-(2 \mu +\lambda) \frac{\partial ^2 u_1}{\partial x_1 ^2}...
Lucas Vieira's user avatar
0 votes
1 answer
3k views

How to use cumtrapz correctly?

I have tried to do a trapeze integration with f(x)=x^2, where I know how the antiderivative looks like, so F(x) = (1/3)x^3 Here's my code, just like I tried: ...
mathflower's user avatar
0 votes
1 answer
256 views

Two RK4 method in one program

I want to solve this integral using RK4 by coding in Fortran: $$R=∫1/a(t) dt → dR/dt=1/a(t) =f(t)$$ Initial point: t=0 (or a=0.001) and R=0 And I have to get a(t) by solving another ...
Elham Q's user avatar
  • 11
2 votes
0 answers
53 views

To use the confluent hypergeometric function or not to?

I am numerically computing the following integral as a function of positive $k$. $$I(k) := \int_0^\infty x^b(k+x)^{a-1} e^{-x} dx \tag1$$ It is shown in math.stackexchange.com that this can be ...
Hans's user avatar
  • 121
3 votes
1 answer
206 views

Time independent Runge Kutta integration of SDE

I am trying to compare the result of numerical integration of time independent Runge_Kutta, github page for stochastic differential equations with the analytical solution. True answer match the ...
Abolfazl's user avatar
  • 131
0 votes
0 answers
27 views

Does order of data points matter for approximating AUC with unit time steps?

I have a time series of data where the increment is every minute. In order to approximate AUC, I just compute the sum of the data values, since they would all be multiplied by 1 anyway per Riemann sum ...
user avatar
1 vote
0 answers
89 views

Plot of ratio of two integrals:

Consider the following integrals $$ I_1(x) =\int_0^\infty\mathrm dy \frac{F(x + \mathrm iy) − F(x −\mathrm iy)}{\mathrm e^{2πy}-1}, $$ And $$I_2(x) =\int_1^x F(t)dt$$ Where, $ F(z) = \sin^2[π\Gamma(z)/...
bambi's user avatar
  • 119
4 votes
0 answers
339 views

How to numerically evaluate this double Integral?

I want to evaluate the following integral: $$\int_{0}^{60} \ \left(\int_{0}^{2z} 0.5\cdot t \left(\mathrm{erf}(t-a) -1 \right)J_{0}(qt)\mathrm{d}t \right)^2 \mathrm{exp}\left(-\frac{(z-a)^2}{2s^2}\...
Shankar_Dutt's user avatar
1 vote
3 answers
294 views

Comparison of integrals with a function:

Consider the following integral: $$S(q)=\int_{x=2}^q\sin^2\left(\frac{π\Gamma(x)}{2x}\right)dx$$ And consider the functions : $$R(q)=\frac{q}{\log(q)}$$ $$T(q)=\int_2^q\frac{1}{\log(x)}dx$$ I ...
bambi's user avatar
  • 119