Instructors
Training Material:
p.ternesdallagnollo@leeds.ac.uk
Â
Practical Project
I want a code that returns the area of a circle for a given radius.
The main requirement is that no predefined value for π should be used.
The value of π (from math/numpy package, for example) can, however, be used to check the accuracy of the result.
The result can have a maximum error of 0.01% compared to standard methods (using π from some package and πr²)
Receive a radius value
Sort a random x-value inside a line of 2*radius size
Sort a random y-value inside a line of 2*radius size
Check if the (x,y) point is inside or outside the circle
If inside, add 1 to a counter
Determine the area by using the proportion of total sorted points and the total number of points inside the circle.
Determine the error between the calculated area and the theoretical area.
If the error is lower than the desired error, stop the code.
If the error is higher, repeat steps from 2 to 6.