Hezekiah Branch
Wed Feb 16 2022
Partial Sums
Purpose: Analyze a given series with useful calculations, including the nth partial sum
Usage: Designed for terminal/command line usage. Clone, unzip, and launch a terminal from repo location.
Alternate Environment(s): Jupyter Notebooks, analysis programs, scripts, etc.
Options: To run the calculation automatically, set the last parameter 'auto' to 'True'.
p = PartialSum(function, lower, upper, auto=True)
>>> from partial_sum import PartialSum
>>> fx = lambda x : (-1)**x / (x)**0.5
>>> p = PartialSum(fx, 1, 1000000, True)
Final result available at .result or by calling 'print()' on PartialSum object.
To view the output of f(x) for each n as n approaches infinity, use .test to view the entire list.
To view the nth partial sum (i.e. the limit if input is a convergent infinite series), use .tail to view output.
To observe if tail approaches zero, use .zero_tail (checks margin of 1e-7).
>>> p.tail
5.000011249218367e-10
>>> p.zero_tail
True
The output from .result integrates well with data analysis and plotting libraries such as pandas and matplotlib.
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> small_data = {i : p.test[i-1] for i in range(p.lower, 100)}
>>> pd.Series(small_data).plot.line(title="Terms of Series Distributed by N", xlim=(1, len(small_data)))
<matplotlib.axes._subplots.AxesSubplot object at >
>>> plt.show()
>>> small_sum_data = {i : p.result[i-1] for i in range(1, 100)}
>>> pd.Series(small_sum_data).plot.line(title="Partial Sums Distributed by N", xlim=(1, len(small_sum_data)))
<matplotlib.axes._subplots.AxesSubplot object at >
>>> plt.show()
In the images above, we have an alternating series with non-increasing term magnitude and a limit that approaches zero, indicating convergence. This tool provides visual artifacts of convergence which can supplement tests such as the Alternating Series Test.
For more information about mathematical analysis and convergence tests, see:
https://en.wikipedia.org/wiki/Alternating_series_test
Citation: Wikipedia contributors. (2022, January 24). Alternating series test. In Wikipedia, The Free Encyclopedia. Retrieved 03:33, February 17, 2022, from https://en.wikipedia.org/w/index.php?title=Alternating_series_test&oldid=1067674590