You’ll see I’ve used Object Oriented Python for this particular exercise, I don’t really know why. Sound good? It’s fairly easy to run this in Python and graph the output using Matplotlib. Using that fact and the formulae for the areas of a circle and a square you can estimate Pi using the ratio of darts in the circle and in the square. We’ll throw darts at that picture randomly you’d expect the number of darts in the circle to be proportional to the area of the circle and the number of darts in the square to be proportional to the area of the square. But there you have it – with that set up we can now start the Monte Carlo bit. A well organised blogger would show you a diagram of this set-up, screw it, this is the code to do it and this is what it looks like:īrilliant – was it worth it? Probably not. Let’s draw a square of side length 2r and a circle centred exactly in the middle of the square with radius r. I was having a think and remembered that you could estimate Pi using a Monte Carlo method and thought like that sounded like the sort of thing I should do. Anyway, I spend a reasonable amount of time on the train with my (oft abused) laptop each morning/evening I don’t have the internet and I don’t have any textbooks so it’s basically a question of what I can work on given only the documentation on my computer and whatever I can remember about programming/maths/stuff. I think there’ll be some unsurprising results. In a later post I’ll chart the effect of Game of Thrones on overall productivity. If you were especially upset then I’m sorry it’s been a while since I posted – I discovered Game of Thrones.
0 Comments
Leave a Reply. |