Skip to content

Commit

Permalink
Merge pull request scipy#9377 from BH4/add-examples-integrate
Browse files Browse the repository at this point in the history
DOC: Add examples integrate: fixed_quad and quadrature
  • Loading branch information
ilayn authored Oct 15, 2018
2 parents 8047001 + 29315bf commit d0bb811
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions scipy/integrate/quadrature.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ def fixed_quad(func, a, b, args=(), n=5):
ode : ODE integrator
odeint : ODE integrator
Examples
--------
>>> from scipy import integrate
>>> f = lambda x: x**8
>>> integrate.fixed_quad(f, 0.0, 1.0, n=4)
(0.1110884353741496, None)
>>> integrate.fixed_quad(f, 0.0, 1.0, n=5)
(0.11111111111111102, None)
>>> print(1/9.0) # analytical result
0.1111111111111111
>>> integrate.fixed_quad(np.cos, 0.0, np.pi/2, n=4)
(0.9999999771971152, None)
>>> integrate.fixed_quad(np.cos, 0.0, np.pi/2, n=5)
(1.000000000039565, None)
>>> np.sin(np.pi/2)-np.sin(0) # analytical result
1.0
"""
x, w = _cached_roots_legendre(n)
x = np.real(x)
Expand Down Expand Up @@ -181,6 +199,20 @@ def quadrature(func, a, b, args=(), tol=1.49e-8, rtol=1.49e-8, maxiter=50,
ode: ODE integrator
odeint: ODE integrator
Examples
--------
>>> from scipy import integrate
>>> f = lambda x: x**8
>>> integrate.quadrature(f, 0.0, 1.0)
(0.11111111111111106, 4.163336342344337e-17)
>>> print(1/9.0) # analytical result
0.1111111111111111
>>> integrate.quadrature(np.cos, 0.0, np.pi/2)
(0.9999999999999536, 3.9611425250996035e-11)
>>> np.sin(np.pi/2)-np.sin(0) # analytical result
1.0
"""
if not isinstance(args, tuple):
args = (args,)
Expand Down

0 comments on commit d0bb811

Please sign in to comment.