Math 1a Spring 2021
1a Introduction to Calculus
Data 04: Monte Carlo
| The fourth Project (PDF) deals with integration. |
In the first part, we use the digits of π as a number generator. Lets illustrate this with taking 3 digit blocks. Here are 60 digits of π.
3.14159265358979323846264338327950288419716939937510582097494We can produce random numbers by building blocks of 3 to get the sequence
141, 592, 653, 589, 793, 238, 462, 643, 383, 279, 502, 884, 197, 169, 399, 375, 105, 820, 974, 944Now we get random numbers by dividing by 1000
x1= 0.141, x2= 0.592 , x3=0.653 etcNow, we can integrate a function like f(x)=x3 numerically by building the sum (∑k=120 (xk)^3)/20. In this case the sum is 0.2338 which is still a bit off from the 0.25 we want to have. But when using more digits this converges. For 600 digits, we get 0.244244, with 1000 digits we get 0.25467. Here is what we get depending on the number of digits. The k'th entry in this block uses 3k digits of π so that we have k numbers xk.
Here is the online python interpreter and here is the python code. Try to tune the parameters to get more accurate results!
| The following picture of the Mandelbrot set was produced with the Ray tracer Povray. You find the source code of a Povray program which produces a movie on this page. The program is so small that it could be tweeted. Here is the tweet and the movie. |
|