Giter Club home page Giter Club logo

quadpy's Introduction

quadpy

Your one-stop shop for numerical integration in Python.

PyPi Version PyPI pyversions GitHub stars PyPi downloads

Discord awesome

More than 1500 numerical integration schemes for line segments, circles, disks, triangles, quadrilaterals, spheres, balls, tetrahedra, hexahedra, wedges, pyramids, n-spheres, n-balls, n-cubes, n-simplices, the 1D half-space with weight functions exp(-r), the 2D space with weight functions exp(-r), the 3D space with weight functions exp(-r), the nD space with weight functions exp(-r), the 1D space with weight functions exp(-r2), the 2D space with weight functions exp(-r2), the 3D space with weight functions exp(-r2), and the nD space with weight functions exp(-r2), for fast integration of real-, complex-, and vector-valued functions.

Installation

Install quadpy from PyPI with

pip install quadpy

See here on how to get a license.

Using quadpy

Quadpy provides integration schemes for many different 1D, 2D, even nD domains.

To start off easy: If you'd numerically integrate any function over any given 1D interval, do

import numpy as np
import quadpy


def f(x):
    return np.sin(x) - x


val, err = quadpy.quad(f, 0.0, 6.0)

This is like scipy with the addition that quadpy handles complex-, vector-, matrix-valued integrands, and "intervals" in spaces of arbitrary dimension.

To integrate over a triangle, do

import numpy as np
import quadpy


def f(x):
    return np.sin(x[0]) * np.sin(x[1])


triangle = np.array([[0.0, 0.0], [1.0, 0.0], [0.7, 0.5]])

# get a "good" scheme of degree 10
scheme = quadpy.t2.get_good_scheme(10)
val = scheme.integrate(f, triangle)

Most domains have get_good_scheme(degree). If you would like to use a particular scheme, you can pick one from the dictionary quadpy.t2.schemes.

All schemes have

scheme.points
scheme.weights
scheme.degree
scheme.source
scheme.test_tolerance

scheme.show()
scheme.integrate(
    # ...
)

and many have

scheme.points_symbolic
scheme.weights_symbolic

You can explore schemes on the command line with, e.g.,

quadpy info s2 rabinowitz_richter_3
<quadrature scheme for S2>
  name:                 Rabinowitz-Richter 2
  source:               Perfectly Symmetric Two-Dimensional Integration Formulas with Minimal Numbers of Points
                        Philip Rabinowitz, Nira Richter
                        Mathematics of Computation, vol. 23, no. 108, pp. 765-779, 1969
                        https://doi.org/10.1090/S0025-5718-1969-0258281-4
  degree:               9
  num points/weights:   21
  max/min weight ratio: 7.632e+01
  test tolerance:       9.417e-15
  point position:       outside
  all weights positive: True

Also try quadpy show!

quadpy is fully vectorized, so if you like to compute the integral of a function on many domains at once, you can provide them all in one integrate() call, e.g.,

# shape (3, 5, 2), i.e., (corners, num_triangles, xy_coords)
triangles = np.stack(
    [
        [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]],
        [[1.2, 0.6], [1.3, 0.7], [1.4, 0.8]],
        [[26.0, 31.0], [24.0, 27.0], [33.0, 28]],
        [[0.1, 0.3], [0.4, 0.4], [0.7, 0.1]],
        [[8.6, 6.0], [9.4, 5.6], [7.5, 7.4]],
    ],
    axis=-2,
)

The same goes for functions with vectorized output, e.g.,

def f(x):
    return [np.sin(x[0]), np.sin(x[1])]

More examples under test/examples_test.py.

Read more about the dimensionality of the input/output arrays in the wiki.

Advanced topics:

Schemes

Line segment (C1)

  • Chebyshev-Gauss (type 1 and 2, arbitrary degree)
  • Clenshaw-Curtis (arbitrary degree)
  • Fejér (type 1 and 2, arbitrary degree)
  • Gauss-Jacobi (arbitrary degree)
  • Gauss-Legendre (arbitrary degree)
  • Gauss-Lobatto (arbitrary degree)
  • Gauss-Kronrod (arbitrary degree)
  • Gauss-Patterson (9 nested schemes up to degree 767)
  • Gauss-Radau (arbitrary degree)
  • Newton-Cotes (open and closed, arbitrary degree)

See here for how to generate Gauss formulas for your own weight functions.

Example:

import numpy as np
import quadpy

scheme = quadpy.c1.gauss_patterson(5)
scheme.show()
val = scheme.integrate(lambda x: np.exp(x), [0.0, 1.0])

1D half-space with weight function exp(-r) (E1r)

Example:

import quadpy

scheme = quadpy.e1r.gauss_laguerre(5, alpha=0)
scheme.show()
val = scheme.integrate(lambda x: x**2)

1D space with weight function exp(-r2) (E1r2)

  • Gauss-Hermite (arbitrary degree)
  • Genz-Keister (1996, 8 nested schemes up to degree 67)

Example:

import quadpy

scheme = quadpy.e1r2.gauss_hermite(5)
scheme.show()
val = scheme.integrate(lambda x: x**2)

Circle (U2)

  • Krylov (1959, arbitrary degree)

Example:

import numpy as np
import quadpy

scheme = quadpy.u2.get_good_scheme(7)
scheme.show()
val = scheme.integrate(lambda x: np.exp(x[0]), [0.0, 0.0], 1.0)

Triangle (T2)

Apart from the classical centroid, vertex, and seven-point schemes we have

Example:

import numpy as np
import quadpy

scheme = quadpy.t2.get_good_scheme(12)
scheme.show()
val = scheme.integrate(lambda x: np.exp(x[0]), [[0.0, 0.0], [1.0, 0.0], [0.5, 0.7]])

Disk (S2)

  • Radon (1948, degree 5)
  • Peirce (1956, 3 schemes up to degree 11)
  • Peirce (1957, arbitrary degree)
  • Albrecht-Collatz (1958, degree 3)
  • Hammer-Stroud (1958, 8 schemes up to degree 15)
  • Albrecht (1960, 8 schemes up to degree 17)
  • Mysovskih (1964, 3 schemes up to degree 15)
  • Rabinowitz-Richter (1969, 6 schemes up to degree 15)
  • Lether (1971, arbitrary degree)
  • Piessens-Haegemans (1975, 1 scheme of degree 9)
  • Haegemans-Piessens (1977, degree 9)
  • Cools-Haegemans (1985, 4 schemes up to degree 13)
  • Wissmann-Becker (1986, 3 schemes up to degree 8)
  • Kim-Song (1997, 15 schemes up to degree 17)
  • Cools-Kim (2000, 3 schemes up to degree 21)
  • Luo-Meng (2007, 6 schemes up to degree 17)
  • Takaki-Forbes-Rolland (2022, 19 schemes up to degree 77)
  • all schemes from the n-ball

Example:

import numpy as np
import quadpy

scheme = quadpy.s2.get_good_scheme(6)
scheme.show()
val = scheme.integrate(lambda x: np.exp(x[0]), [0.0, 0.0], 1.0)

Quadrilateral (C2)

Example:

import numpy as np
import quadpy

scheme = quadpy.c2.get_good_scheme(7)
val = scheme.integrate(
    lambda x: np.exp(x[0]),
    [[[0.0, 0.0], [1.0, 0.0]], [[0.0, 1.0], [1.0, 1.0]]],
)

The points are specified in an array of shape (2, 2, ...) such that arr[0][0] is the lower left corner, arr[1][1] the upper right. If your c2 has its sides aligned with the coordinate axes, you can use the convenience function

quadpy.c2.rectangle_points([x0, x1], [y0, y1])

to generate the array.

2D space with weight function exp(-r) (E2r)

Example:

import quadpy

scheme = quadpy.e2r.get_good_scheme(5)
scheme.show()
val = scheme.integrate(lambda x: x[0] ** 2)

2D space with weight function exp(-r2) (E2r2)

Example:

import quadpy

scheme = quadpy.e2r2.get_good_scheme(3)
scheme.show()
val = scheme.integrate(lambda x: x[0] ** 2)

Sphere (U3)

Example:

import numpy as np
import quadpy

scheme = quadpy.u3.get_good_scheme(19)
# scheme.show()
val = scheme.integrate(lambda x: np.exp(x[0]), [0.0, 0.0, 0.0], 1.0)

Integration on the sphere can also be done for functions defined in spherical coordinates:

import numpy as np
import quadpy


def f(theta_phi):
    theta, phi = theta_phi
    return np.sin(phi) ** 2 * np.sin(theta)


scheme = quadpy.u3.get_good_scheme(19)
val = scheme.integrate_spherical(f)

Ball (S3)

Example:

import numpy as np
import quadpy

scheme = quadpy.s3.get_good_scheme(4)
# scheme.show()
val = scheme.integrate(lambda x: np.exp(x[0]), [0.0, 0.0, 0.0], 1.0)

Tetrahedron (T3)

Example:

import numpy as np
import quadpy

scheme = quadpy.t3.get_good_scheme(5)
# scheme.show()
val = scheme.integrate(
    lambda x: np.exp(x[0]),
    [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.5, 0.7, 0.0], [0.3, 0.9, 1.0]],
)

Hexahedron (C3)

Example:

import numpy as np
import quadpy

scheme = quadpy.c3.product(quadpy.c1.newton_cotes_closed(3))
# scheme.show()
val = scheme.integrate(
    lambda x: np.exp(x[0]),
    quadpy.c3.cube_points([0.0, 1.0], [-0.3, 0.4], [1.0, 2.1]),
)

Pyramid (P3)

  • Felippa (2004, 9 schemes up to degree 5)

Example:

import numpy as np
import quadpy

scheme = quadpy.p3.felippa_5()

val = scheme.integrate(
    lambda x: np.exp(x[0]),
    [
        [0.0, 0.0, 0.0],
        [1.0, 0.0, 0.0],
        [0.5, 0.7, 0.0],
        [0.3, 0.9, 0.0],
        [0.0, 0.1, 1.0],
    ],
)

Wedge (W3)

Example:

import numpy as np
import quadpy

scheme = quadpy.w3.felippa_3()
val = scheme.integrate(
    lambda x: np.exp(x[0]),
    [
        [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.5, 0.7, 0.0]],
        [[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [0.5, 0.7, 1.0]],
    ],
)

3D space with weight function exp(-r) (E3r)

Example:

import quadpy

scheme = quadpy.e3r.get_good_scheme(5)
# scheme.show()
val = scheme.integrate(lambda x: x[0] ** 2)

3D space with weight function exp(-r2) (E3r2)

Example:

import quadpy

scheme = quadpy.e3r2.get_good_scheme(6)
# scheme.show()
val = scheme.integrate(lambda x: x[0] ** 2)

n-Simplex (Tn)

Example:

import numpy as np
import quadpy

dim = 4
scheme = quadpy.tn.grundmann_moeller(dim, 3)
val = scheme.integrate(
    lambda x: np.exp(x[0]),
    np.array(
        [
            [0.0, 0.0, 0.0, 0.0],
            [1.0, 2.0, 0.0, 0.0],
            [0.0, 1.0, 0.0, 0.0],
            [0.0, 3.0, 1.0, 0.0],
            [0.0, 0.0, 4.0, 1.0],
        ]
    ),
)

n-Sphere (Un)

Example:

import numpy as np
import quadpy

dim = 4
scheme = quadpy.un.dobrodeev_1978(dim)
val = scheme.integrate(lambda x: np.exp(x[0]), np.zeros(dim), 1.0)

n-Ball (Sn)

Example:

import numpy as np
import quadpy

dim = 4
scheme = quadpy.sn.dobrodeev_1970(dim)
val = scheme.integrate(lambda x: np.exp(x[0]), np.zeros(dim), 1.0)

n-Cube (Cn)

Example:

import numpy as np
import quadpy

dim = 4
scheme = quadpy.cn.stroud_cn_3_3(dim)
val = scheme.integrate(
    lambda x: np.exp(x[0]),
    quadpy.cn.ncube_points([0.0, 1.0], [0.1, 0.9], [-1.0, 1.0], [-1.0, -0.5]),
)

nD space with weight function exp(-r) (Enr)

Example:

import quadpy

dim = 4
scheme = quadpy.enr.stroud_enr_5_4(dim)
val = scheme.integrate(lambda x: x[0] ** 2)

nD space with weight function exp(-r2) (Enr2)

Example:

import quadpy

dim = 4
scheme = quadpy.enr2.stroud_enr2_5_2(dim)
val = scheme.integrate(lambda x: x[0] ** 2)

quadpy's People

Contributors

nschloe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quadpy's Issues

classes -> functions?

All quadrature scheme classes do nothing else than setting the data in __init__. Would we lose anything when converting all classes to functions that return the respective scheme?

Heuristics for when to use certain schemes?

Hi, thanks for the great package!

Are there any resources for those of us who are looking to play around with different rules without diving deep into the literature? I don't understand the distinctions between many of the formulae (except of course the salient parts like order), and I'm not sure how to learn the distinction without combing through the original papers. Thanks!

example no longer working

I only checked this for quadrilateral as it's the only one I use, but probably needs adjustment in other examples as well:

val = quadpy.quadrilateral.integrate(
    lambda x: numpy.exp(x[0]),
    quadpy.quadrilateral.rectangle_points([0.0, 1.0], [-0.3, 0.6]),
    quadpy.quadrilateral.Stroud(6)
    )

in the readme does no longer work as the indices refer to the indices in Stoud's publication (such as 'C2 7-3'). Furthermore an explanation of index ordering would be nice, as this changed from the old versions of this package.

Like in: "Rectangle points are now given in [x0,x1][y0,y1] order" (If I assume correctly)
In old versions it was [[x0,y0][x1,y1][x2,y2][x3,y3]]; this might be confusing. At least for me it was.

Integral calculation result is not correct.

print(quadpy.line_segment.integrate(lambda x: scipy.exp(1j*x), [-1, 100],quadpy.line_segment.GaussKronrod(3)))

The code is for calculating integral of exp(j*x) from -1 to 100, however, it returned a wrong value:

(-11.219936196799733+10.78170013544869j)

According to wolframalpha, the result should be:

(0.335105 - 0.322017j)

But the result of the code provided by Nico Schlömer in stackoverflow is correct:

val = quadpy.line_segment.integrate(
        lambda x: scipy.exp(1j*x),
        [0, 1],
        quadpy.line_segment.GaussKronrod(3)
        )
print(val)

result:

(0.841470984808+0.459697694132j)

Am I missing something?

quadpy doesn't import

I recently installed quadpy on windows 8.1 with Anaconda3 distribution of Python and running the spyder script.
When i try to run the first example of the readme:

import numpy
import quadpy

def f(x):
    return numpy.sin(x[0]) * numpy.sin(x[1])

triangle = numpy.array([[0.0, 0.0], [1.0, 0.0], [0.7, 0.5]])

val = quadpy.triangle.integrate(f, triangle, quadpy.triangle.Strang(9))`

I found the following text:

_Traceback (most recent call last):

  File "<ipython-input-4-c9a12b6d6ed4>", line 2, in <module>
    import quadpy

  File "C:\Anaconda3\lib\site-packages\quadpy\__init__.py", line 24, in <module>
    from . import line_segment

  File "C:\Anaconda3\lib\site-packages\quadpy\line_segment\__init__.py", line 7, in <module>
    from .gauss_kronrod import GaussKronrod

  File "C:\Anaconda3\lib\site-packages\quadpy\line_segment\gauss_kronrod.py", line 6, in <module>
    from orthopy import jacobi_recursion_coefficients, gauss_from_coefficients

ImportError: cannot import name 'jacobi_recursion_coefficients'_

I would appeciate any help.

Usage question

I would like to use this library to find a sudo numerical Laplace transform of some discrete data. So I know that I would need a weight function of

Whight=lambda sigma, omega: scipy.exp(sigma+1j*omega)

but how would I construct the kernel around f which is my input data 1D vector but besides that I have no idea on how to set this up with quadpy using the Quadrilateral or the RabinowitzRichter integration scheme or if its even doable

so for exsample by f data may be given by

f=np.linspace(0,5,150)

as a basic exsample

Integration of function only accepting transposed points.

Hi!

Thanks for a great module - it's very impressive!

I have a question. Currently the integration relies on the integrand being defined as in your example:

def f(x):
    return np.sin(x[0]) + np.cos(x[1])

where the numpy vectorisation takes care of input vectors of shape x.shape = (2, N).
I am currently dealing with functions that assume the input is of shape x.shape = (N, 2), as in the following example:

def f(x):
    return np.sin(x[:, 0]) + np.cos(x[:, 1])

yielding errors like

    def integrate(f, simplex, scheme, dot=numpy.dot):
        flt = numpy.vectorize(float)
        x = transform(flt(scheme.points).T, simplex.T)
        vol = get_vol(simplex)
>       return vol * dot(f(x), flt(scheme.weights))
E       ValueError: shapes (2,) and (7,) not aligned: 2 (dim 0) != 7 (dim 0)

Would it be possible to support functions that accept ''transposed'' input?

Missing schemes

computation of monomials

Right now, the monomials are computed this way:

  1. Exponent pairs are generated for all n.
  2. These vectors are concatenated.
  3. The exponents are applied individually to an array x.

Recurrence relations of orthogonal polynomials provide a better idea, for example in 2D: The table

       (0, 0)
   (1, 0)  (0, 1)
(2, 0) (1, 1) (0, 2)
 ...    ...    ...

can be constructed from top to bottom by simply multiplying elements from one row by x (or y) and appending one more element to the left or the right. Although recurrent (and hence not parallelizable), this should be way more efficient.

Missing Lebedev quadratures

Hi,

Although not quite my expertise area, I think the code cannot generate some basic Lebedev quadratures.

Most simple of these being, just a single node at the origin.

Also:

{
  "a3": [
    [5.7735026918962575e-01]
  ],
  "degree": 2
}

and:

{
  "a2": [
    [7.07106781186547524e-01]
  ],
  "degree": 4
}

In both cases degree is just an arbitrary number that I have written in order to make it work with your code.

I came across this issue when I was trying to implement the algorithm described in https://aip.scitation.org/doi/full/10.1063/1.5008630.

[Feature] Use Knuth summation by default instead of Kahan

Kahan provides less digits and needs more time. However, by default quadpy use Kahan only https://github.com/nschloe/quadpy/blob/6d49cc07e96d644bdcf039fd66a541208ce96794/quadpy/helpers/misc.py#L50

Can probably be ported from C code below.

https://www.mathworks.com/matlabcentral/fileexchange/26800-xsum

  • Kahan: The local error is subtracted from the next element. 1 to 3 more valid digits, 2 to 9 times slower.
  • Knuth: As if the sum is accumulated in a 128 bit float: about 15 more valid digits. 1.4 to 4 times slower. This is suitable for the most real world problems.

perform as many tests as possible with orthogonal polynomials

It is well known that the map from the monomials integrals to integration formulas is ill-conditioned (see, e.g., Gautschi who pointed it out in great detail for Gaussian rules). Hence, sanity tests in quadpy can be improved by not checking against monomial integrals, but integrals of orthogonal polynomials.

  • line segment
  • triangle
  • tetrahedron
  • hexahedron
  • quadrilateral
  • pyramid
  • wedge
  • n-ball
  • n-cube
  • n-sphere
  • sphere
  • circle
  • ball
  • disk

n-simplex: Vioreanu/Rokhlin

SIAM J. SCI. COMPUT. c 2014
Vol. 36, No. 1, pp. 267-288
SPECTRA OF MULTIPLICATION OPERATORS AS A NUMERICAL TOOL
B. VIOREANU AND V. ROKHLIN

tanh-sinh: better approximation of initial h

Right now, the basis for the approximation is the approximated representation of j (with lambertw). One might however also also be able to take the fully accurate cosh-representation of j as a basis. A Newton-iteration is done anyways.

Too many subscripts for einstein sum

Hi Nico,

I wanted to use quadpy for my integrations. I tried the line_integral example given in the readme. It gives me a ValueError: einstein sum subscripts string contains too many subscripts for operand 0.
I am not sure what is going wrong. Any ideas?

Thanks.

How to make an integration over a parametric line in 3D?

Hello, I have a complex-valued function which argument is a 3D point. I want to do an integration of it over a line segment (parametrized in t). I get a ValueError: operands could not be broadcast together with shapes (3,) (1,15) . Here is the sample code:

import numpy
from scipy import linalg
import quadpy

startPoint = numpy.array([0.5, 1.0, 1.2])
endPoint = numpy.array([-0.5, -1.0, 0.7])
length = linalg.norm(startPoint - endPoint)
gamma = 0.01 + 0.586j

def point(t):
    return startPoint + (endPoint - startPoint)*t

def integrand(t):
    pt = point(t)
    r1 = linalg.norm(pt - startPoint)
    r2 = linalg.norm(pt - endPoint)
    nf = (r1 + r2 + length)/(r1 + r2 - length)
    return numpy.log(nf)*numpy.exp(-gamma)

value, error_estimate = quadpy.line_segment.integrate_adaptive(integrand,[0,1],1e-10)

The error is raised because t is passed as an array. If I try to vectorize the point function using numpy.vectorize, then the error changes to ValueError: setting an array element with a sequence.. I can't think of a work around. Could you help me?

generate more digits

The nonlinear optimization problem from Witherden-Vincent/Papanicodopulos can be used.

Quadpy out of sync with orthopy since newest release

Since the most recent release of orthopy (0.2.0, two days ago), calls to orthopy.recurrence_coefficients.jacobi() no longer accept the 'mode' keyword argument (and potentially more has stopped working, but this is the first thing I ran into):

File "/usr/local/lib/python2.7/dist-packages/quadpy/line_segment/gauss_kronrod.py", line 47, in __init__ orthopy.recurrence_coefficients.jacobi(length, a, b, mode='numpy') TypeError: jacobi() got an unexpected keyword argument 'mode'

Suggested fix: specify orthopy 0.1.7 as requirement in setup.py for the time being, then update quadpy to work with the newest release of orthopy.

Thanks!

Error in Gauss-Hermite formula?

Hi,

I'm using quadpy 0.12.5
Maybe I'm missing something, but I think there's an issue with the way the Gauss-Hermite integration is coded.

When looking at the wikipedia page, I see there should be a Pi^(-0.5) term added and a rescaling of the gauss-hermit points.

import quadpy
import numpy as np
from scipy import stats
from scipy import integrate

def f(x):
    return x**2

#Manual Gauss-Hermite
points, weights = np.polynomial.hermite.hermgauss(5)
mu, sigma = 0, 1
rescaled_points = np.sqrt(2)*sigma*points + mu

manual_gauss_hermite = np.pi**(-0.5)*np.dot(f(rescaled_points), weights)

#Manual trapezoid
xvals = np.linspace(-10, 10, num=100)
yvals = f(xvals) * stats.norm.pdf(xvals)
trapezoid_int = integrate.trapz(yvals, xvals)


#Gauss-Hermite integration
quadpy_integration = quadpy.e1r2.integrate(f, quadpy.e1r2.GaussHermite(5))


print("Manual Gauss-Hermite: ", manual_gauss_hermite)
print("Trapezoid: ", trapezoid_int)
print("Quadpy Integration: ", quadpy_integration)

gives

Manual Gauss-Hermite:  0.9999999999999999
Trapezoid:  1.0
Quadpy Integration:  0.8862269254527577

So the trapezoid rule agrees with the rewrite of gauss-hermite, but not with the gauss-hermite procedure contained in quadpy.

n-simplex: Möller/Grundmann

A. Grundmann and H.M. Moeller, Invariant integration formulas for the n-simplex by combinatorial methods, SIAM J. Numer. Anal. 15 (1978), 282–290.

Vectorized integration

I stumbled upon your project in Stack Overflow when looking for a way to calculate integrals over arrays. Sadly it is poorly documented, so I have troubles finding out how to do the integration.

I have a function f(x: complex) -> np.ndarray which returns a ndarray of shape (N_l, N_e). How can I integrate this function? I tried

quadpy.line_segment.integrate_adaptive(
    f,
    [0, 1],
    1e-8
)

as well as

quadpy.line_segment.integrate_adaptive(
    lambda x: f(x).reshape(-1),
    [0, 1],
    1e-8
)

in both cases it complains over the mismatch of dimensions. Is there a way to calculate the integral?

Heo/Xu

Generating quadratures

Thanks for this software!

I cannot create custom quadratures using the scheme proposed in the documentation.

See the section: Generating your own Gauss quadrature in three simple steps

I am using quadpy 0.11.4 and orthopy 0.5.3.

add symbolic=True/False keyword to all schemes

Right now, numpy.vectorize(float) must be called for each integration since the scheme may return the points and weights symbolically. This may take a while. To avoid this, add the keyword symbolic=True/False to all schemes and compute the points and weights accordingly.

  • line segment
  • triangle
  • tetrahedron
  • hexahedron
  • quadrilateral
  • pyramid
  • wedge
  • n-ball
  • n-cube
  • n-simplex
  • n-sphere
  • sphere
  • circle
  • ball
  • disk
  • e1r
  • e2r
  • e3r
  • enr
  • e1r2
  • e2r2
  • e3r2
  • enr2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.