Thursday 1 September 2016

Simulation with Excel Series: Final Lab Funtime!

Title: Simulate the path (Random Walk) of a drunkard.

Basic Theory:
In this lab, we try to simulate the motion of a drunkard in two dimensions, which depicts Random Walk. A drunkard can move in any direction without proper thought and we try to simulate this process using a random function which determines the next step of the drunkard. It is an example of Markov Chain because the prior motion of the drunkard does not influence its current motion.  

Procedure:
For simulation of drunkard’s random walk, we first specify an initial position with randomly distributed values of motion in X and Y directions (dx and dy). These will characterize that the drunkard moves randomly in a two-dimensional space. This can be described using a random function in Excel as,

dx =1-2*RAND()
dx =1-2*RAND()

The next values of X and Y are calculated as
Xi = Xi-1 + dxi
Yi = Yi-1 + dyi

This formula shows that the points will be plotted with respect to their last values, and the values prior to that do not make direct contributions. Hence, we can observe the Markov property in Brownian motion.

After that, we generate a Scatter plot of the X and Y values and see the drunkard’s motion. We can experiment with values of dx and dy to see the changes in the behavior of particle motion.

Thus, we were able to visualize a drunkard’s random walk using random distribution and assuming Markov property.

Sample Data:
Table1: Sample Data for drunkard’s motion is
dx
dy
X
Y
0.838546
-0.32853
0
0
0.673706
-0.94962
0.673706
-0.94962
-0.59668
0.811554
0.077027
-0.13807
-0.59386
0.346488
-0.51683
0.208419
0.78065
0.295288
0.26382
0.503707
-0.16151
0.428357
0.102307
0.932064
-0.11278
0.908384
-0.01047
1.840448
-0.17453
0.235414
-0.18501
2.075862
-0.76316
-0.10395
-0.94817
1.971913
-0.44464
-0.53974
-1.3928
1.432171

Output:

Below are the graph plots for drunkard’s motion up to 300 steps:


Conclusion:
Hence, we could see that the Drunkard’s motion was consistent with the random values of dx and dy. The more the values of dx and dy deviate in each new step of the drunkard, the obtained curve gets more zig-zag.

Wednesday 17 August 2016

Simulation with Excel Series: Lab 4 Brownian Motion

Title: Simulation of Brownian motion of smoke particles.

Basic Theory:
In this lab, we try to simulate the motion of multiple particles in two dimensions, which depicts Brownian motion. Brownian motion is a stochastic model in which changes from one time to the next are random draws from a normal distribution. It is a physical phenomenon which can be observed, for instance, when a small particle is immersed in a liquid. The particle will move as though under the influence of random forces of varying direction and magnitude. There is a mathematical idealization of this motion that allows us to simulate the successive positions of a particle undergoing Brownian motion. It is an example of Markov Chain.  

Procedure:
For simulation of Brownian motion, we first specify a collection of random particles with randomly distributed values of motion in X and Y directions (dx and dy). This will characterize that the particles move randomly in a two-dimensional space. This can be described using a random function in Excel as,

dx =1-2*RAND()

We can use dx =1-3*RAND() for a more scattered motion. This is same for y as well.
Now, we assign the drift values for X and Y points. They will further define the movement of particles due to some specific drift forces that act on them. So, the positions of particles are defined by

Xn = Xn-1 + Drift(x) + dx
Yn = Yn-1 + Drift(y) + dy

This formula shows that the points will be plotted with respect to their last values, and the values prior to that do not make direct contributions. Hence, we can observe the Markov property in Brownian motion.

After that, we generate a Scatter plot of the X and Y values and see the particle motion. We can experiment with drift values to see the changes in the behavior of particle motion.

Thus, we were able to visualize Brownian motion using random distribution and assuming Markov property.

Sample Data:
Table1: Sample Data for Brownian motion is
dx
dy
X
Y
-0.89132
-0.9203
0
0
0.208206
-0.7602
1.208206
0.239804
0.021238
-0.78757
2.229443
0.452233
-0.78564
0.614743
2.443803
2.066976
0.765821
0.259244
4.209624
3.32622
-0.2025
0.748862
5.007128
5.075081
-0.03483
0.09562
5.972299
6.170702
-0.89046
-0.70513
6.081844
6.465568

Output:

Below are the graph plots for Brownian motion for 300 particles:


Conclusion:
Hence, we could see that the Brownian motion of particles was consistent with chosen drift values. The more the drift in any one direction, the obtained curve gets wavier. We can further increase the precision of the simulation by increasing the number of random points, thus being able to observe larger number of particles. However, the excel worksheet will become too slow if we generate a lot of random numbers because of large number of calculations.  

Wednesday 3 August 2016

Simulation with Excel Series: Lab 3 Estimating Integrals

Title: Estimating the value of integrations of different functions using Monte Carlo Simulation.

Basic Theory:
In this lab, we are trying to find the value of integration of a linear and a quadratic function using Monte Carlo Simulation. The Monte Carlo simulation deploys the concept of a large collection of random data that satisfy some property to perform simulations in diverse fields including computer science. In this case, we are applying it for Mathematical analysis of estimating the value of area under the curve i.e. integration.

Procedure:
For estimating the value of integration, we first specify a square area and plots random points inside it. We have used 1000 points in this simulation. It is still very simple because we plot the points in specific regions with well defined ranges for X and Y coordinates. We then use absolute referencing to generate random values within the range. This can be described using a random function in Excel as,

X = $X$0+($X$1-$X$0)*RAND()
This is similar for y as well.

Now, we plot the points which fall within the region satisfied by the equation of the function. So, for the equation y = x the description of the Excel formula will be,

Y = =IF(Yn<Xn,Yn,0)

This formula shows that the points will be plotted only if they satisfy y = x. Now we can perform our calculation as,

Integration = n/N*c(b-a)
Where, c is height, b and a are x-ranges. Also, c(b-a) is the area of rectangle here.

We now count the points under the curve using,
n = COUNTIF(Y0:Y1000,"<>0" )

So, integration will be n/1000 * Area of Rectangle.

Hence, we found the value of value of integration for y = x. We can use the same process to find the value of integration for the curve y = x2 except that we have to use Y = IF(Yn<Xn^2,Yn,0).

Sample Data:
Table1: Sample Data for Monte Carlo Simulation for finding integration value for y = x.
X
Y
Curve X
Curve Y
3.172925628
4.756267552
3.172925628
0
4.025446279
1.020977669
4.025446279
1.020977669
4.859458217
4.077230586
4.859458217
4.077230586
0.660807938
5.691479042
0.660807938
0
2.835472595
0.202967389
2.835472595
0.202967389
4.46133673
5.299769082
4.46133673
0
2.104981223
0.039854532
2.104981223
0.039854532
2.920367193
6.808772442
2.920367193
0
2.426309885
0.417571468
2.426309885
0.417571468

Output:

Below are the graph plots for the points below the curve y = x and y= x2.


Results:
The results of our simulation were,
Curve
Simulated Value
Actual Value
y = x
12.39
12.5
y = x2
5250
5208.33