[SciPy-user] Integration with precalculated values

Robert Kern robert.kern@gmail....
Mon Jun 16 18:18:54 CDT 2008


On Mon, Jun 16, 2008 at 18:10, Mico Filós <elmico.filos@gmail.com> wrote:
> Hi,
>
> I need to evaluate this function for an array of ys
>
>    f(y) = integral( exp(x*x)  * psi(x), A -y, B -y) # 2nd and 3rd
> arguments: lower and upper limits
>
> where
>
>    psi(x) = integral( exp(t*t) * ( 1 + erf(t) )**2 , -Inf, x)
>
> Apart from the fact that the integrand blows up easily, I would gain
> some speed by
> precalculating psi for the ranges I need for the computation of f(y).
> Is there any proper way to do that?

Only if you can afford to give up adaptive sampling. Then you can use
fixed_quad() for Gaussian quadrature over your function (it will do
just one vectorized evaluation), or trapz(), simps() or romb() for
uniform samples that you have computed yourself. If your function
blows up easily, though, you may not be able to afford to give up on
adaptive sampling.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco


More information about the SciPy-user mailing list