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
5
votes
3answers
226 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)}\\ =\...
0
votes
0answers
20 views

Using Pymc3+Theano+astropy for Bayesian inference with integral expressions

This is my first time using Pymc3 or Theano, so I apologize if this question is straightforward. I'm interested in using Bayesian inference to see how effective the (non) observation of something can ...
0
votes
0answers
70 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 ...
1
vote
1answer
70 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 ...
6
votes
0answers
86 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 ...
1
vote
1answer
91 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 ...
2
votes
0answers
29 views

Sample Average Approximation vs. Numerical Integration

In the sense of the calculation of the expected value of objective functions, we have two choices to evaluate the value; 1. Sample Average Approximation (SAA): $$ \frac{1}{N}\sum_{i=1}^N f(x,\xi^i). $$...
2
votes
1answer
908 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 ...
1
vote
1answer
47 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 =...
0
votes
1answer
59 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 ...
-1
votes
1answer
88 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....
5
votes
0answers
378 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\|\,...
0
votes
2answers
134 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)$. ...
2
votes
3answers
191 views

Calculating the antiderivative numerically

HeIIo everybody, in the standard literature topics like numerical differentiation and numerical integration are usually discussed in detail. However, numerical integration is not the same as ...
0
votes
1answer
89 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^{...
1
vote
1answer
92 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)$ ...
5
votes
0answers
130 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. ...
0
votes
0answers
54 views

How to efficiently perform this 2D integral in Quadpy?

I need to integrate a function defined in 2Dims (z and radius r), for which I don't have an expression. I can just query the ...
2
votes
0answers
100 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, ...
-1
votes
1answer
133 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....
3
votes
2answers
488 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-...
0
votes
2answers
113 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 ...
1
vote
1answer
149 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} (...
1
vote
1answer
67 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}^{...
0
votes
0answers
11 views

Different values of Gaussian Integration in Pracma library in R

I want to construct a gauss integration for the weight function: $$w(x) = x^{1/2}$$ $\in(0,1)$ of the form: $$\int_{0}^{1}x^{1/2}f(x)dx = w_{1}f(x_{1})+w_{2}f(x_{2})$$ \begin{align*} w_{1}+w_{2} =...
1
vote
1answer
388 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 ...
2
votes
0answers
98 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 ...
0
votes
0answers
33 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 (...
1
vote
1answer
109 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 ...
1
vote
1answer
870 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^{\...
3
votes
1answer
136 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 ...
2
votes
1answer
92 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) +...
0
votes
0answers
93 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 ...
3
votes
1answer
311 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 ...
1
vote
0answers
73 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 ...
2
votes
2answers
234 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}$$ ...
1
vote
0answers
114 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 ...
0
votes
2answers
171 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}...
0
votes
1answer
328 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: ...
0
votes
1answer
158 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 ...
2
votes
0answers
40 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 ...
3
votes
1answer
79 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 ...
0
votes
0answers
21 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 ...
1
vote
0answers
79 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)/...
5
votes
0answers
133 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}\...
2
votes
3answers
270 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 ...
2
votes
1answer
454 views

Performing 2d numerical integration with Boost Cpp

I've been learning to use the numerical quadrature of the Boost library for Cpp. In the documentation, I've found an example for 1D Gauss-Kronrod Quadrature using Boost. ...
0
votes
3answers
92 views

Changing variables in integral to avoid infinity

I want to write a code in Fortran to solve this integral numerically: $$\int_{1095}^\infty \frac{dx}{x\sqrt{(x+644.153)(4.17 \cdot 10^{-5} x+0.145)}}$$ What is the best method for it? I tried Monte-...
2
votes
1answer
917 views

Vectorised second order ode solving in python

I am trying to write a python program that simulates the motion of a large number of particles by numerically integrating a second order ordinary differential equation. I first split the ODE into two ...
2
votes
1answer
198 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'...