Questions tagged [integral]

This tag should be used for questions related to coding solutions for integrals.

In numerical analysis field, algorithms for integration are a typical example of use for this tag. See also:

819 questions
3
votes
0 answers

How do I integrate numerically a function in Python?

I'm trying to write a Python code (based on a Mathematica notebook) that includes some integrations, but I had no luck so far. The integral I'm trying to evaluate is: where, *It's for Bjorken-Mtingwa Intra-beam scattering calculations. In Python,…
Michalis Z
  • 51
  • 6
3
votes
1 answer

How to compute integral of partial derivative in R?

First time trying out the Deriv package. I was trying to compute a very simple integral of partial derivative as a start: Here's my attempt: junk <- function (m) { -m*eval(deriv(~((exp(0.1*(100-94.5)^2))/(exp(0.1*(100-94.5)^2)+exp(0.1*…
wearpants
  • 33
  • 4
3
votes
1 answer

Multiple integration with functions of variables in the limits

I need to numerically integrate the following: I tried to use cubature and pracma but they don't seem to support functional integration limits. I found a attempt to use cubature by: library(cubature) integrand <- function(arg) { x <- arg[1] …
3
votes
1 answer

Retrieve integral expression of a function

Base R provides a function D() that outputs the expression of the derivative of a given function. For example: f <- expression(x^3+2*x) D(f, "x") # with respect to x # 3 * x^2 + 2 Is there a similar function that would yield the expression of the…
Fred
  • 410
  • 3
  • 12
3
votes
2 answers

Incorrect answer from Monte Carlo integration

How can I approximate the integral of [x^4 * sin(x)]/ [exp(1)^(x/5)] (0 to +Inf) with Monte Carlo method in R? What I tried to do is set.seed(666) func1 <- function(x) { (x^4 * sin(x))/exp(1)^(x/5) } n <- 1000000 x <- rexp(n, 0.2) f…
Incognite
  • 41
  • 1
  • 3
3
votes
2 answers

Efficient way for calculating integrals?

I know how to use the Monte-Carlo to calculate integrals, but I was wondering if it is possible to use the trapezium rule combined with numpy for efficiency to get the same integral, I am not sure which one is the fastest or is the latter…
JKM
  • 45
  • 4
3
votes
0 answers

Use the Gauss-Laguerre quadrature to approximate an integral in R

I am using the Gauss-Laguerre quadrature to approximate the following integral I wrote the function in R int.gl<-function(x) { x^(-0.2)/(x+100)*exp(-100/x) } First, I used integrate() function to get the "true" value, which I double check with…
C.C.
  • 55
  • 9
3
votes
1 answer

How to check if a SymPy expression has analytical integral

I want to solve my other question here so I need sympy to return an error whenever there is no analytical/symbolic solution for and integral. For example if I try : from sympy import * init_printing(use_unicode=False, wrap_line=False,…
Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
3
votes
1 answer

Trapezoidal Riemann Sum in C

I've been trying to do Riemann Sums to approximate integrals in C. In my code below, I'm trying to approximate by both the trapezoidal way and the rectangular way (The trapezoidal way should be better, obviously). I tried making an algorithm for…
defunct-user
  • 183
  • 1
  • 11
3
votes
0 answers

R: speeding up integrate function

I need to speed up a function. Especially the part of the integrals. Like you can see I have to integrate from 0 to Inf for different parameters every time. I already vectorized the function. But it still runs quite slow. I already tried a parallel…
V Kuhn
  • 55
  • 1
  • 7
3
votes
2 answers

Sympy and Wolframalpha give different result

Sympy and wolframalpha have produced different result. Have done anything obviously wrong here? import sympy as smp smp.init_printing() In [2]: a,R,t = smp.symbols('a,R,t',real=True) In [3]: f = t**2/(1+t**2/a**2);f Out[3]: In…
pranphy
  • 1,787
  • 4
  • 16
  • 22
3
votes
3 answers

Is there an algorithm to calculate the area of a Lissajous figure?

Suppose I have measurements of two signals V = V(t) and U = U(t) that are periodic in time with a phase difference between them. When plotted against each other in a graph V vs U they form a Lissajous figure, and I want to calculate the area…
3
votes
1 answer

Numerical integration in R : bad integrand behaviour error

This is my matrix func=structure(c(-14.7690673280818, -14.5543581356252, -12.1406211639974, -10.7200919648493, -9.55507848352318, -9.20790894914246, -8.74647670464071, -8.26548763467919, -7.3962484443768, -6.94590909664862, -6.63903257406218,…
Joao Baptista
  • 33
  • 1
  • 4
3
votes
0 answers

Coordinate transformation in a double integral using sympy

How do I do a coordinate transformation (cartesian to polar) in a double integral using sympy? For example, from: Integral(exp(-x**2-y**2), (x,-oo,oo), (y,-oo,oo)) To: Integral(exp(-r**2)*r, (r,0,oo), (t,0,2*pi))
3
votes
1 answer

Vectorization of double for loop including sine of two variables

I need to numerically evaluate some integrals which are all of the form shown in this image: These integrals are the matrix elements of a N x N matrix, so I need to evaluate them for all possible combinations of n and m in the range of 1 to N. The…
M-P
  • 53
  • 6