In [1]:
import adaptive_trapezint_new as p1
import sinesum1_new as p2
import centered_diff_new as p3
import find_primes_new as p4
Improves on the trapezoidal integration rule by creating a method to determine an apropriate $n$ trapezoids. The table shows the error of the estimation and the calculated $n$ for three different cases.
In [2]:
p1.table()
Consider the following piecwise function:
$ f(t) = \left\{\def\arraystretch{1.2}% \begin{array}{@{}c@{\quad}l@{}} 1 & 0<t<\frac{T}{2}\\ 0 & t=\frac{T}{2}\\ -1 & \frac{T}{2}<t<T\\ \end{array}\right. $
Approximate $f(t)$ by the sum $$S(t,n)= \frac{4}{\pi} \sum_{i=1}^{n} \frac{1}{2i-1} sin{\frac{2(2i-1)\pi t}{T}}$$
Display the error $f(t)-S(t,n)$ for various $n$ and $\alpha$, given that $t=\alpha T$ and $T=2 \pi$. Use $n=1,3,5,10,30,100$ and $\alpha = 0.01, 0.25, 0.49$.
In [3]:
p2.table()
The formula $$f'(x) \approx \frac{f(x+h)-f(x-h)}{2h}$$ approximates a derivative a function $f(x)$ if $h$ is small. Use $h=0.01$ and show the error for the approximations of the following functions:
In [4]:
p3.table()
Use the $\mathit{Sieve\ of\ Eratosthenes}$ to find prime numbers less than or equal to a number $N$.
In [5]:
print p4.find_primes(10)
In [6]:
print p4.find_primes(50)
In [7]:
print p4.find_primes(100)
In [ ]: