There is a wealth of information out there on plotting mathematical functions in Python, typically using NumPy to create a set of y values for a range of x values and plotting them with Matplotlib. In this article I will write a simple but powerful function to abstract away much of the repetitive code necessary to do this. In future articles I will show the code in use for a selection of functions.
In the first part of this article I wrote code to calculate rough estimates of square roots which enable formulas which converge on accurate square root values to do so with fewer iterations. Part 1 also included code to graph estimates to compare them to accurate values.
In this second part I'll implement some of those formulas, again graphing the results alongside definitive values.
Python provides us with a perfectly satisfactory method of calculating square roots, the math.sqrt() method, but in this pair of articles I will explore some of the ways square roots can actually be calculated from scratch. In this first article I will look into a few ways of calculating rough estimates which form a starting point or "seed" for the methods I'll examine in Part 2.
The Ancient Greek polymath Eratosthenes of Cyrene made the first serious attempt at calculating the size of the Earth. Using very simple observations and mathematics he achieved a surprisingly accurate result and in this article I will replicate his calculations in Python.
In this project I will code in Python a few of the methods of estimating Pi.
Pi is an irrational number starting off 3.14159 and then carrying on for an infinite number of digits with no pattern which anybody has ever discovered. Therefore it cannot be calculated as such, just estimated to (in principle) any number of digits.
The numbers in the graphic below form the first five rows of Pascal's Triangle, which in this post I will implement in Python.
The first row consists of a single number 1. In subsequent rows, each of which is has one more number than the previous, values are calculated by adding the two numbers above left and above right. For the first and last values in each row we just take the single value above, therefore these are always 1.
Pascal's Triangle in its conventional centred layout