hi guys i need help writing a Monte Carlo for area under a curve
define the curve define a space that accommodates the curve start throwing darts keep track of (accumulate) the darts that are 'under' and 'over' the curve monitor ratios: under/over, under/total space, over/total space, (over + under) / total space stop throwing darts when you think you have enuff.
thank you one more question how would one do if say for example my function is \[f(x) = 2x + 1\] with an interval \[[-2, 2]\]. Sorry im completely new to python
do you understand the concept? http://en.wikipedia.org/wiki/Numerical_integration http://en.wikipedia.org/wiki/Monte_Carlo_integration if you just want a complete solution, try a search for - Monte Carlo integration python break the problem down (like i did above) and try to write discrete pieces of code to solve each. then put them together. things to consider: - how to define a function? - how to define the encapsulating space? - how to accumulate the 'darts' - do you need a data structure? or more than one? which? - do need to iterate? while, for loops? or recursion? -
Join our real-time social learning platform and learn together with your friends!