Can you help me on the Numerical Analysis question

82 Views Asked by At

The question: The error function defined by $$erf(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^{2}} dt. $$ The error function can also be formed as a series. $$ \frac{2}{\sqrt{\pi}} \sum_{k=0}^{\infty} \frac{(-1)^{k}x^{2k+1}}{(2k+1)k!} $$. The series can also be formed as $$ \frac{2}{\sqrt{\pi}} e^{x^{2}} \sum_{k=0}^{\infty} \frac{2^k x^{2k+1}}{1 \cdot 3\cdot 5 \cdots (2k+1)} $$

Use the series to approximate the $\text{erf}(1)$ to within $10^{-7}$

The Attempt: I have no idea how to set a bound for each series. Do I have to use the Remainder Theorem for Taylor Series? Please give me hints on how to solve this problem. Thank you very much!

3

There are 3 best solutions below

3
On

When $x=1,$ the absolute values of the terms of the first series form a positive monotonic decreasing sequence, and the terms themselves are alternating $+-.$ So the error after summing from $k=0$ to $k=n$ is between $0$ and the value of the next term ($k=n+1$). So for the absolute value of the error, we have $$|erf(1)-\sum_{k=0}^n\frac {(-1)^k}{(2k+1)k!}| <\frac {2}{\sqrt \pi}\frac {1}{(2n+3)(n+1)!}$$ which is less than $10^{-7}$ for $n\geq 9.$

For the second series, for convenience write it as $erf(x)=(2/\sqrt \pi)e^{x^2}\sum_{k=0}^{\infty}A_kx^{2k+1}.$ Observe that $A_{k+1}=2A_k/(2k+3).$

When $n$ is large enough that $2x^2/(2n+5)<1$ we have $$|\sum_{k=n+1}^{\infty}A_kx^{2k+1}|=|x^{2n+3}A_{n+1}|\cdot |(1+\frac {2x^2}{2n+5}(1+\frac {2x^2}{2n+7}(1+...)|\leq $$ $$\leq |x^{2n+3}A_{n+1}|\cdot |1+\frac {2x^2}{2n+5}(1+\frac {2x^2}{2n+7}(1+..)|=$$ $$=|x^{2n+3}A_{n+1}| \sum_{j=0}^{\infty}(\frac {2x^2}{2n+5})^{-j}.$$ The last series, above, is geometric.

0
On

For the second sum, $\frac{2}{\sqrt{\pi}} e^{x^{2}} \sum_{k=0}^{\infty} \frac{2^k x^{2k+1}}{\prod_{j=0}^k (2j+1)} $, if $a_k =\frac{2^k x^{2k+1}}{\prod_{j=0}^k (2j+1)} $, then $\frac{a_{k+1}}{a_k} =\frac{2x}{2k+3} $.

If $k > mx$, then $\frac{a_{k+1}}{a_k} <\frac{2x}{mx} <\frac{2}{m} $. Therefore, If $k > mx$, then $\frac{a_{k+j}}{a_k} <(\frac{2}{m})^j $, so, to bound the tail of the series,

$\begin{array}\\ \sum_{k=mx}^{\infty} a_k &<\sum_{k=mx}^{\infty} a_{mx}(\frac{2}{mx})^{k-mx}\\ &=a_{mx}\sum_{k=0}^{\infty} (\frac{2}{mx})^{k}\\ &=a_{mx}\frac{1}{1-2/(mx)}\\ \end{array} $

If you far enough out so $a_{mx}$ is small, this bounds the tail. Throwing in the $e^{x^2}$ bounds the whole thing.

So, given $x$, find an $m$ so that this tail is small enough.

This is moderately crude, but should be a good start.

0
On

Cocenrning the first problem, starting from @user254665's answer, what you want is to find $n$ such that $$\Big|\text{erf}(1)-\sum_{k=0}^n\frac {(-1)^k}{(2k+1)k!}\Big| <\frac {2}{\sqrt \pi}\frac {1}{(2n+3)(n+1)!}=\epsilon$$ that is to say $$(2n+3)(n+1)!=\frac{2}{\sqrt{\pi} \epsilon}\tag1$$ Taking logarithms and using Stirling approximation, this can write $$\frac{5}{2} \log \left({n}\right)+n (\log (n)-1)+\log \left(2 \sqrt{2 \pi }\right)=\log\left(\frac{2}{\sqrt{\pi} \epsilon}\right)$$ This is then equivalent to finding the zero of equation $$f(n)=\frac{5}{2} \log \left({n}\right)+n (\log (n)-1)+\log \left(\sqrt{2} \pi \epsilon \right)$$ $$f'(n)=\frac{5}{2 n}+\log (n)$$ Use Newton method and being very lazy, let us start using $n_0=1$. The successive iterates will then be (for $\epsilon=10^{-7}$) $$\left( \begin{array}{cc} k & n_k \\ 1 & 7.2507 \\ 2 & 8.3515 \\ 3 & 8.3295 \end{array} \right)$$

while the exact solution of $(1)$ would be $n=8.1870$. Hence $n=9$ as given by @user254665.

Another solution could be obtained writing $$(2n+3)(n+1)!\approx (2n+4)(n+1)!=2(n+2)!=\frac{2}{\sqrt{\pi} \epsilon}\tag2$$ that is to say $$\Gamma(n+3)=\frac{1}{\sqrt{\pi} \epsilon}\implies n+3=\Gamma^{-1}\left(\frac{1}{\sqrt{\pi} \epsilon}\right)$$ and to use the nice approximation of the inverse gamma function as proposed by David W. Cantrell. This would give $n=8.1853$.