In [3]:
import walk2Dv as wlk
import numpy as np
import matplotlib.pyplot as plt
import flip_coin_vec as fcv

Classwork 10

Sakthi and Will

Problem 1.

Simulate a coin flip N times, and write out the number of tails. All code should be vectorized.

The code for this one was very short and fairly straightforward. Here are the results of ten flips, carried out ten times.


In [5]:
for i in range(0,10):
    print(fcv.flipCoin(10))


5
6
6
4
5
7
7
7
5
3

Problems 2 and 3.

Simulate the random walk problem in 2 dimensions, using vectorized code where possible. Then create a Gif of the random walk for 1000 particles taking 400 steps.

The code I implemented was a cleaned-up version of the code in the book. I also went a little nuts with ImageMagick and subsequently FFMpeg. Without further ado, here is a gif of 1000 particles taking 400 steps each: