-1
$\begingroup$

While solving an exercise problem from here, I stumbled upon a problem in the evaluation of:

$$ \int_0^u \frac{1}{\sqrt{1 + x^p}} dx \approx \sum_{k=1}^N {\frac{1}{1 + (x_k^*)^p} \Delta x} $$

where $ \Delta x = \frac{u}{N} $ and $ x_k^* = \frac{x_k + x_{k - 1}}{2} $ for endpoints $ x_k = k \Delta x $ using Python.

Note: $x_k^* = \frac{x_k + x_{k - 1}}{2} = \frac{\Delta x(2k - 1)}{2}$

For a test case, plugging $u = 1, p = 2$ yields $\int_0^1 \frac{1}{\sqrt{1 + x^2}} dx \approx 0.8813$


Have a look at my code:

def sqrt_integral(N, upper, p):
    "Evaluates the integral of 1/sqrt(1 + x^p) from 0 to u."

    dx = upper / N
    term = [dx / (1 + ((2*k - 1)*dx / 2)**p) for k in range(1, N + 1)]

    summation = sum(term)
    return summation


print(sqrt_integral(10000, 1, 2))

The term is a list comprehension that evaluates each term in the form:

$$ \sum_{k=1}^N \frac{\Delta x}{1 + \left(\frac{\Delta x(2k - 1)}{2}\right)^p} $$

Now, I don't understand why it yields $\approx 0.7853$.

$\endgroup$
2
  • 3
    $\begingroup$ Have you missed out the square root in your approximation? $\endgroup$
    – mcd
    Mar 29, 2023 at 6:29
  • 1
    $\begingroup$ But the Riemann sum for $\int f(x) dx$ is the limit of the sum of the areas of the rectangles with height $f(x)$ and appropriate width, so I think you need the square root in your sum. $\endgroup$
    – mcd
    Mar 29, 2023 at 8:30

1 Answer 1

2
$\begingroup$

The formula for the Riemann sum should be

$$\int_{x=a}^b f(x) \, dx = \lim_{N \to \infty} \sum_{k=1}^N f(x_k^*) \Delta x, \tag{1}$$ where $\Delta x = \frac{b-a}{N}$, $x_k^*$ is defined as you have done, and $x_k = a + k \Delta x$.

In your case, $a = 0$, $b = 1$, and $$f(x) = \frac{1}{\sqrt{1+x^2}}.$$ This makes the sum $(1)$

$$\lim_{N \to \infty} \sum_{k=1}^N \frac{1}{\color{red}{\sqrt{1+(x_k^*)^2}}} \Delta x. \tag{2}$$

Try it out. You will find that the result numerically matches.

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .