Numerically Evaluating Functions Like $I(x)=(\int_0^xf(x^\prime)\mathrm{d}x^\prime)/x$ near $x=0$

48 Views Asked by At

Like the title says, I'm interested in numerically evaluating the function $$I(x)=\frac{\int_0^xf(x^\prime)\mathrm{d}x^\prime}{x}$$ where $f(x^\prime)$ is given by the user as sampled points and is greater than zero at $x=0$ so that this function evaluates to a finite value. The trouble is that near $x=0$ both the numerator and denominator become small and lead to trouble, especially when you are actually at $x=0$.

I could obviously Taylor expand in this region, but using a piecewise expression feels like a kluge and means I can't fully take advantage of vectorized math to speed things up due to the if-statement.

Is there some global way of re-writing this function that makes it safe for numerical evaluation near $x=0$?

1

There are 1 best solutions below

3
On

We can use the MVT for integrals to get that $$\int_0^x f(x')\mathrm{d}x'=xf(c)$$ For some $c \in (0,x)$. This guarentees that $$\lim_{x \to 0} I(x)=f(0)$$ If $f$ is continuous.