Stochastic Simulation

Published by Arun Isaac on

Tags: c, tcl, gnuplot, project, software

This is a loose collection of programs we wrote as part of a course on "Stochastic Models" we had in the fourth semester of college. This includes a couple of pseudo random number generators (the Von Neumann middle square PRNG and the linear congruential generator PRNG), an implementation of the Monte Carlo method to determine area of an arbitrarily shaped figure and a simple simulation of birth-death process.

Screenshot of the LCG Pseudo Random Number Generator

Figure 1: Screenshot of the LCG Pseudo Random Number Generator

This is a loose collection of programs we wrote as part of a course on "Stochastic Models" we had in the fourth semester of college. Some of it was written just to aid in a deeper of understanding of the concept, some others for assignment and some others just for fun. This includes a couple of pseudo random number generators (the Von Neumann middle square PRNG and the linear congruential generator PRNG), an implementation of the Monte Carlo method to determine area of an arbitrarily shaped figure and a simple simulation of birth-death process.

Of special interest is the 'stochsim.c' library which served as the backbone of the birth-death process simulation. Basically, it has functions to simulate a variety of random experiments, especially those involving random variables. Once the 'stochsim.c' library was written, the birth-death process simulation was just a series of function calls to 'stochsim.c'. 'stochsim.c' is written in a pretty generalized manner and has scope for application in other stochastic simulations as well. If you ever find it useful in any of your own coding, I would love to hear.

These programs owe their simple and elegant plots to the beauty of the shell pipeline. The C program does the calculations and outputs the numerical results to stdout which are piped to a data file. Then gnuplot is made to plot the data file. In the case of the two PRNGs, Tcl/Tk implements a simple GUI interface.

Downloads