kigochen / WynnEpsilon

Implementation of Wynn's Epsilon Method For Convergence Acceleration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contact

Patrick Lohr: pjlohr@email.arizona.edu

Implementation of Wynn's Epsilon Method For Convergence Acceleration

For most convergent series, the rate of convergence can be accelerated by applying the Shanks Transformation, which approximates the limit of a sequence in a non-linear fashion. That is, for a series of the form:

The Shanks Transformation is defined as:

Where Ap are the pth partial sums of the sequence, and ΔAp = Ap+1 - Ap. This gives a method to solve for the kth-order Shank's Transformation. Peter Wynn introduced an efficient algorithm for computing the kth Shanks Transformation of a partial sum and is given by the following:

Here, each ε2k is the equivalent of applying the kth Shanks Transformation to the nth partial sum Sn. ε0 is defined as Sn, and the primary diagonal gives the next approximation. For this example, take the Gregory-Leibniz series for calculating π:

This series will eventually converge to π, but it will take billions of terms to get even a decent a approximation! Just take a look at http://www.eveandersson.com/pi/gregory-leibniz. After 1000 terms, the series is only accurate to 2 decimal places. Even after 109 iterations, the approximation only reaches 8 decimals of precision.

wynnpi.py takes an integer argument N and implements Wynn's epsilon method to find a highly precise approximation for π after N terms of the Gregory-Leibniz series. Make sure to include NumPy.

Expected Behavior

(biosystems-analytics) Patricks-MacBook-Pro:14-open patricklohr$ ./wynnpi.py -h
usage: wynnpi.py [-h] [-n INT]

Wynn Epsilon for Gregory-Leibniz series

optional arguments:
  -h, --help            show this help message and exit
  -n INT, --numterms INT
                        Number of series terms (1<=n<=22) (default: 10)
(biosystems-analytics) Patricks-MacBook-Pro:14-open patricklohr$ 
(biosystems-analytics) dhcp-10-142-223-217:14-open patricklohr$ ./wynnpi.py -n 22

Series approximation for π (22 terms):      3.096161526463642
Wynn Epsilon accelerated result (22 terms): 3.141592653589795
Actual Value:                               3.141592653589793
Relative Error:                              7.067899292141149e-16

(biosystems-analytics) dhcp-10-142-223-217:14-open patricklohr$ 

Test Suite

(biosystems-analytics) Patricks-MacBook-Pro:14-open patricklohr$ make test
pytest -v test.py
============================ test session starts ============================
platform darwin -- Python 3.7.2, pytest-4.3.1, py-1.8.0, pluggy-0.9.0 -- /Users/patricklohr/
anaconda3/envs/biosystems-analytics/bin/python
cachedir: .pytest_cache
rootdir: /Users/patricklohr/Documents/Repo/biosys-analytics/assignments/14-open, inifile:
collected 3 items                                                           

test.py::test_usage PASSED                                            [ 33%]
test.py::test_bad_input PASSED                                        [ 66%]
test.py::test_good_input PASSED                                       [100%]

========================= 3 passed in 0.59 seconds ==========================
(biosystems-analytics) Patricks-MacBook-Pro:14-open patricklohr$ 

About

Implementation of Wynn's Epsilon Method For Convergence Acceleration

License:MIT License


Languages

Language:Python 97.7%Language:Makefile 2.3%