Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum inside an integral. #6

Open
carlosRmelo opened this issue Nov 19, 2020 · 0 comments
Open

Sum inside an integral. #6

carlosRmelo opened this issue Nov 19, 2020 · 0 comments

Comments

@carlosRmelo
Copy link

carlosRmelo commented Nov 19, 2020

Hello,

It is possible passing and array as argument to a function? Something like that:

import numpy as np
import pyquad


def test_integrand_func(x, alpha, beta, i, j, k, l):
    a = np.sum(i)
    return x * alpha * beta + a * j * k



grid = np.random.random((10, 2))

i = np.array([1,2,3])

res, err = pyquad.quad_grid(test_integrand_func, 0, 1, grid, (i,1,1,1))

This is just a toy example. My problem actually is that i have a sum inside an integral, and i have to evaluate this integral over a grid of values (x,y). For now I'm using scipy.quad, but for a large grid the code is going very slow. Bellow I have pasted a more realistic example of I want to do.

Screenshot from 2020-11-19 14-44-24

import numpy as np
from scipy.integrate import quad


def fun(tau, x, y, alpha, beta):
    """
    x: int
    y: int
    alpha: array
    beta: array
    """
    x_til = x/alpha
    y_til = y/beta
    aux = (x_til**2 + y_til**2)
    exp = np.exp(- tau**2*aux)
    
    return (tau**2)*exp.sum()



grid = np.random.random((10, 2))

alpha = np.array([1,2,3])
beta = np.array([4,5,6])

res = np.empty_like(grid)

for i in range(len(grid)):
    res[i] = quad(fun, 0, 1, args=(grid[i][0],grid[i][1], alpha, beta))

Any help is welcome, and thanks in advance.

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant