Definite integral of $\tan(x)$

84 Views Asked by At

I'm not sure where to ask this question, stackoverflow or here. However, because the question appeared when trying to solve a math problem, I'll post my question here:

I'm trying to verify that $$\int_\frac{\pi}{6}^\frac{\pi}{3} \tan(x) \, dx = \frac{1}{2} \ln(3) \approx 0.549,$$ using Riemann sum $$\lim_{n\to\infty} \sum_{i=0}^{n-1} \tan\left( \frac{\pi}{6} + \frac{\pi}{6} \frac{i}{n}\right) \frac{1}{n}.$$ So I wrote the following Python code:

import numpy as np
n = 10000
steps = np.arange(n) / n
X = np.pi / 6 + np.pi / 6 * steps
print((np.tan(X) / n).sum()) # 1.049039723834813

As you can see the code output is around $1.049$, not $0.549$, so what did I do wrong? I don't think it's numeric underflow, because I have tried different $n$ values, including $100$ and $999999.$

1

There are 1 best solutions below

1
On BEST ANSWER

Inside the tan, you are using $\frac\pi6\frac1n$ as your step size ($\Delta x$). So on the outside, you should use the same step size. A fix would be $$ \lim_{n\to\infty}\sum_{i=0}^{n-1}\tan\left(\frac\pi6+ \frac\pi6\frac in\right)\frac\pi6\frac1n. $$ All in all, you were off by a factor $\pi/6$.