simplylobi.blogg.se

Matlab calculate pi given a quarter circle in a square
Matlab calculate pi given a quarter circle in a square









matlab calculate pi given a quarter circle in a square

Then finding what’s inside the circle is just a simple sqrt(x^2 + y^2) < 1. I find it much easier to think of it with a quarter of a circle (origin at ) within a square (with corners at ,]). Not sure if this even requires an image but eh…

matlab calculate pi given a quarter circle in a square

The logic is as follows: knowing the area of a perfect circle, radius r, and the area of a perfect square, length r, one can find Pi using the ratio of the areas. I make no allusions here, it’s basically like writing ‘Hello World’ in the algorithm world. I’ve happened to use Monte Carlo methods to help predict battery life in electric vehicles, but as usual in engineering you mostly use the tools instead of creating them, and I wanted to try it out… so I decided to do find Pi using Monte Carlo Simulation. This is usually easier than calculating the ‘accurate picture of the solution’ and at the same time it gives much better accuracy and granularity of outcomes as opposed to just following the boundaries such as ‘best-case scenarios’ and ‘worst-case scenarios’. It can get quite complicated in application but overall summary is throwing a lot of random sample points at a problem until you get a ‘rough picture of the solution’. Rarified gas flows (where it can’t be modelled as a fluid and modelling each individual molecule is prohibitive).Animation and video game ray tracing (modelling a sample of photons as it bounces around the room).Calculate risk in finance and logistics.Monte Carlo methods/simulations/experiments, are basically using randomly distributed samples to solve problems which otherwise might be quite difficult so solve using analytical means, like very complex multi-dimensional integrations, or to calculate overall uncertainty of a large number of small events with different probabilities. Lately been mostly using python, so to not let the knowledge of Matlab slip away I thought I should do minor exercises also in Matlab…In this case, I chose to approximate Pi using Monte Carlo methods, another quick 30min project! Monte Carlo methods











Matlab calculate pi given a quarter circle in a square