# 102 lab8

Notes on Lab #8

For this lab, you will turn in your models (Excel spreadsheet or Vensim model) and your writeup as usual.

Area through Monte Carlo Simulation

For this part you will use Monte Carlo simulation to compute the area (integral) of a function over a given interval. In order to verify your simulation, you could use one of the arbitrarily generated integrable functions from integrals.wolfram.com as a test case. (You may have to keep hitting the RANDOM EXAMPLE button till you get a function that’s easy to work with.) Or if you remember enough calculus, just use an integral familiar to you. You can use Excel or Vensim to do the simulation, but in either case you should use a sufficient number of points (10,000 should be enough) and report:

1. the function you used
2. the interval over which you computed the area
3. a plot of the function over that interval
4. the number of points in your simulation
5. the analytical form of the integral from Wolfram
6. the area from the simulation
7. the value obtained by analytical solution for the definite integral from the Fundamental Theorem of Calculus
8. the relative error.

For reporting the function and its integral, you may way to use Microsoft Equation Editor in Word (Insert /Object / Microsoft Equation), which formats the symbols nicely. If you use Vensim and it doesn’t allow you to display a sufficient number of values to see the final relative error, include a plot of how this error decreases as you use more points. If you use Excel, you can generate 10,000 random values as follows:

1. Put =RAND() in the first row of a column
2. Select the whole column by clicking on the header (letter) at the top
3. In the Home tab, click the Fill button at right, and select Down
4. Scroll down to row 10,001 and delete values from there to the end of the column

Random Walks

Use Vensim to build a model to generate data to make an average-distance-traveled plot like the one on p. 412 (last of these slides). Hint: Have two “populations”, x and y, each with its own inflow, but no arrow from the population to the inflow. For each number of steps, take the average over five random seeds. You should also turn in a sample plot of the walk itself, by doing an X/Y graph similar to the one you did for the skydiving and predator/prey models. You can look at a limited number of steps (10 – 20) to save time and simplify the the X/Y plot. If you’re good at Excel, you may be able to use one of the spreadsheets from the authors’ repository instead of Vensim, but the trick will be to figure out how to generate the X/Y plot from the animation. If you have time, you might try a “biased random walk” where there’s a higher probability of moving in a certain direction.