 Let us now simulate random walk using the random number generator. For illustration purposes we take a simple one dimensional random walk. We also try both symmetric as well as asymmetric random walk. To recapitulate a random walk is basically jump on a discrete lattice. The jump length in each ith attempt we call it as sigma i or ith step sigma i equal to either plus 1 or minus 1 with the probability. Let us say p here with the probability q such that p plus q is always 1. And if p equal to q equal to half it is a symmetric or else it is a symmetric or random walk with bias. So, what is random walk? It is nothing but the sum of this displacements sigma i. So, we say that x i. So, some x in n steps is nothing but i equal to 1 to n of the values of sigma i is obtained in each step either plus 1 or minus 1 in simplest fashion. But the plus 1 and minus 1 need not occur all the time with equal probability. If you decide to have a forward bias then more often the plus 1s will occur. So, that will be p more than half case. So, likewise both can be simulated using a random number generator. And that is what we will the kind of program we have to write that is what I will show in Mathematica. So, this is the program here some let us say 500 step random walk has to be generated. Here I consider p set is a value which you assign if it is 0.5 it is for symmetric. And if you put say 0.6 then it means that the forward jumps are higher than the backward jumps. Instead if you put say 0.4 that is less than 0.5 then it is the other way backward jumps will be more often than the forward jumps. We will see why what is this p set when we go along. So, this is basically a beginner to a do loop to start with some integer and some initial values of sigma. Then you start with any x initial displacement. So, you enter a do loop here with the label 2. So, print n and x generate a random number. So, R m is now a command random is a command which generates a random number R m. Now the sigma that is a sigma i which I mentioned in my previous slide is a jump length at the ith trial or ith step. So, that is decided by an if command. If the random number I generated is less than p set then please it says jump 1 if it is more than p set otherwise the the contrary of that then it will take minus 1. So, in this case p set is 0.5 and if R n is less than 0.5 that is all the values of the random numbers occurring below 0.5 it will jump left ah it will jump plus 1 forward or else it will jump minus 1. So, if p set is more than 0.5 let us say 0.6 then random numbers will occur 60 percent more often between 0 and 0.6. So, it will be then forward jumping it will taking 1 value 60 percent and the minus 1 value 40 percent of the times that is how this p set number makes use of the property of uniform distribution of the R n generated. Since it is cumulative is proportional to x itself p set cleverly helps us to decide ah to execute to both symmetric as well as ah asymmetric random walks. So, once p sig is noted for each jump then we simply add it to the previous displacement x is now the displacement from the origin from the starting point. So, x equal to x plus sigma accumulates ah is a displacements if adds or subtracts depending on the value of sigma obtained it can be any of the plus or minus 1 then the whole process random walk continues n equal to n plus 1 and you have to stop when you want. So, here n s is taken as 500. So, it simply generates 500 such steps ah 500 displacements yes. So, we can see some printouts is very simple printout here. So, each step number you can print out and the value of in fact, you can add many things if you want sigma values obtained in each case also you can print out for any analysis if you want to do correlation studies and all then x n also you can print out the total displacement it has suffered at nth step that information is also available. So, this can go on and on simulation is it does not talk of probabilities right you will generate probabilities based on the grouping of this x n and all that. So, here it is just every every trajectory can be obtained this way. So, next ah we can see that this is now left left one is a symmetric random walk with the P equal to 0.5. These are some 5 4 values generated about 4 of the each of them is a 500 ah step walker and a single step if you see it may not ah single graph or path this is one of the paths the 500 steps. You can see lots of internal wiggles as well and there are wiggles at various levels if you go on resolving there is a lot of self similarity that you will see. However, the paths can be totally different in the next sequence of trials you are doing and paths not only they can be one sided in any one of them they can even be multiply crossing the origin quite a few times. Hence in order to estimate the character we have to now do statistical analysis of all this. So, basically the stochastic simulation is over the rest what remains is statistical analysis that is how the mean and the variance of this ah ensembles averages ah can be obtained. ah You can convince yourself that it will satisfy with all the theoretical results that we have got that x bar equal to 0 and I mean sufficiently large or it will be normally distributed around the true mean all that central limit theorem aspects will also come and the ah main point is x n square bar will be proportional to n itself that will also ah emerge from these things ah number of such trials you have to execute ensembles you need to generate ah might vary 5 sometimes may not be sufficient. But that is a matter of detail, but basic process of generation is what we intended to learn and that we have done here. Same thing you can execute for a symmetric random walk you look at a slight difference instead of 0.5 we took p equal to 0.55 here and we can already see a tendency to move one only in positive direction because it was a forward walk. So, sufficiently large number of steps almost direct ah the motion ah along the direction and that is why we called ah p excess over q as a virtually equivalent to a forward velocity or a forward drift in when we went to continuous formalism. If p was less than 0.55 I mean less than 0.5 say 0.45 what would have seen a downward drift like this ah like a backward motion. So, many such interesting features you can simulate by a simple program using the random number generator ah and summing of the displacements. So, just we leave it here ah innumerable exercises can be done. Here the idea is to give ah basic very basic understanding of how to use a random number generator. Now, we perform a numerical simulation of another aspect of stochastic studies that is probabilistic analysis. These were all path generating analysis basically random path generating analysis, but we also saw that matter of actual practical interest is probability distributions. So, we developed random walk equation for occupancy probabilities then we moved over to Fokker Planck equation and for probability densities and once probability densities are obtained directly then you do not need to look for different paths. So, that is the idea. So, it is interesting to know how to solve some practical problems ah of for probability densities. So, that we ah consider a case of gambler's ruin. So, we take a case of a gambler's ruin in which a gambler is sandwiched between two end points either getting ruined we call it as the lower end point or hitting is fortune, hitting is target fortune or winning the game which which will be a large ah amount, but it will be upper end point. So, we can consider simulation of of gambler's ruin ah that is why I forgot. Solution to gambler's ruin problems via Fokker Planck equation approach. So, this is numerical solution we have obtained certain analytical solutions, but we do it via numerical solution. So, to recapitulate we have a two boundaries this is a ruin and this is win and gambler starts from somewhere goes on betting like random walking actually. And if he strikes at the ruin if he gets ruined then the game stops he no longer is able to walk. Similarly, if he wins also the game stops because he has already won and he walks away. So, we we have solved it as a ultimate probability problem by random walk methods. However, it could be of practical interest to see what is the probability that he wins in a finite step interval or finite time interval that is a little difficult to do by discrete step methods. It is somewhat easier to execute it by via Fokker Planck equation because we have developed the Fokker Planck equation approach as a continuum approximation to discrete walk approaches. So, once we go that it becomes now a problem of solving a differential equation basically. However, when we do that it is no longer just the gambler's ruin it is becomes equivalent to a two absorber problem of random walker two absorber we can call it. So, 0 an absorber and the I mean what ruin the ruin is a ruin and that is ruin and win both are absorbers. So, we now therefore, consider it as transport problem basically of a random walking particle or a diffusing particle. Let us for symmetry purposes keep the absorber as a length 2 L from minus L to L let the origin be located here particle can start from any point x naught and it diffuses with a certain diffusion coefficient d which is basically a mapped from the random walking equation L square by 2 tau. There may be a forward bias there may be a may not be it may be a what I mean to say is it is symmetric or asymmetric random walk and we ask a question what is the probability that the random walker touches L from which he cannot come back once he touches in a certain time interval t. So, it is a finite time gambler's ruin problem finite time or you can call it as step gambler's ruin problem we can do it systematically in binumerical methods. For that we have to set up the corresponding differential equation we do it as follows we revisit the subject of the Fokker Planck quickly and remember that the FP equation for the problem now statement formulation the diffuser starts in a domain let us say minus L to L, but we can call it as minus 1 to 1 also this is now the 0 and it starts from some point x naught and its desire to find the probability of him reaching 1 and I will tell you how to normalize all this. So, original differential equation for W x t the probability density that he is at any point x at time t was diffusion equation d 2 W by dx square and if there is a preponderance of one direction or winning streak or losers misfortune then we can accommodate it by a velocity term or a drift term we said which is basically P minus Q kind of thing into d by d. If we solve this differential equation where W is the probability under the initial condition W x 0 was delta x minus x naught where it starts from and the boundary condition W minus 1 t or plus 1 t ok. Let us write it separately W minus 1 t equal to 0 and W plus 1 t also is 0 basically well let us say minus L right now we are talking of x coordinates. So, we will not call it minus 1 minus L to plus L this is ruin then also the game stops this is win. Now of course, this the equation 1 can be easily standardized we can define a dimensionless length xi equal to x by L that is why I wrote minus 1 and plus 1 here in the xi coordinate. So, I call it as now xi naught it is not x naught and this is now xi. My time also changes to a dimensionless time which will be dt by L square and the velocity gets replaced by a Peclet number P equal to U L by d with that the equation becomes d W by d tau equal to now it becomes parameter free d 2 W by d xi square minus Peclet number d W by d xi with the same initial conditions that W xi 0 equal to delta xi minus xi naught and W minus 1 tau equal to W 1 tau will be 0. So, it is a well defined problem of solving now a differential equation we have mapped the gambler's law is problem or gambler's ruin problem to a differential equation problem. So, it is virtually like a transport equation now in one dimension where particle has diffusion and a drift. So, it is like a convective diffusion equation mathematically speaking, but with with meanings and implications are drawn from the original problem. I just tell you how to solve this problem in Mathematica the many ways of doing it. Mathematica has ready made inbuilt commands so I have used them for solving and in the next few minutes we will discuss the results and the way to write a program for handling this from here to PPTs. So, here is the outline of a program this is a program used is a written in a very condensed fashion to fit to page kind of thing. So, you have to define the Peclet number. So, this is a equivalent of a gambler's ruin Fokker Planck equation you can call it as a diffusion plus bias between 2 absorbers. We did not solve it so far actually it is amenable to analytical solution also by Eigen function expansion methods or Fourier series methods it is very long winded. So, I did not produce reproduce it here, but it is possible to obtain the solution and compare it with the numerical also we are not done it, but here we only illustrated the numerical method. So, you start with a Peclet number let us say it can be 0 if it is 0 it is symmetric random walk here the number 5 is given then see here the sig is nothing, but instead of direct delta function you take a very sharp Gaussian with very small sigma. So, it is basically a starting point is at minus half now slightly towards the left he starts because the aim is to reach right. So, we want to see how he manages to reach right even though he his position is unfavorable to that, but his bias is favorable to that because it is a positive bias. So, it will drive him towards that. So, this is original distribution this is some and time for the all dimensionless time now x also is a dimensionless x is xi actually time is tau and this is the domain minus 1 to 1 all scaled by L square by d and Peclet is scaled by u Peclet number is u L by d. Then, Mathematica is a very useful differential equation solver numerically there is a D solve for analytical solving and N D solve for numerical solving command and it is basically D f by D t D for differential here the subscript t is for with respect to time. So, it is nothing, but partial derivative of f with respect to D is a partial derivative of f with respect to x twice d 2 f by dx square here it is Peclet number and D by dx of D by dx of f here and with the initial condition f is f naught x f 1 t is 0 f minus 1 t is 0 etcetera the function f in the domain of x minus 1 to 1 and time between 0 and t naught t naught we have taken as just 1 unit it needs to be solved. Then of course, it extracts the data or the function that it is generated when numerically solving it is extracting out it is a space time profile of the probability then our matter of interest is the probability of contacting the upper point 1 because 1 is the winning surface or winning point. So, it has to obtain that current which is by fixed law equivalently is minus D f by dx. So, it evaluates D f by dx at x equal to 1 that is the absorption current probability of arrival at 1 per unit time. So, it is probability density it is also known as the first passage time distribution function. So, many interpretations to this derivative. So, now having done that for further integrating I did not use the Mathematica command it was sometimes very much more time consuming it was much easier to use Gauss quadrature far more accurate or I would not say far more accurate quite accurate I took 64 point Gauss quadrature it is very very dense and it can evaluate any integral in the domain of minus 1 to 1 by summing over some you know Gauss quadrature in itself one has to know this is not the place I cannot teach you here, but the main idea of Gauss quadrature is it there are some preset points on which the function has to be evaluated and then you have to simply sum over that evaluated function with suitable weights W i corresponding to that point. So, the entire integral is ready to reduce to summing, but summing much more accurately than let us say Simpson summing or any such thing then that is what Gauss quadrature is all about. So, those points are given here 64 values are given you can have even 16 point Gauss quadrature much smaller ones exist 11 point and all, but here we took 64 and similarly the weights for those 64 points are given the function is evaluated though the survival probability in space is defined as the integral of whatever is surviving in f x. So, survival probability space integrated probability density. So, that is available here s t then you can integrate the current to obtain the winning probability in a time t that win the probability is nothing, but the integral over the current that we defined earlier and all this is done. These are the roots just I to show you all the 64 they are available in handbooks. So, you can just develop one zone program these are the x points all the space nodes actually 64 nodes between minus 1 to 1 and here you can see 64 weights for all those nodes then the after the program is over you plot. So, various quantities are plotted we will just see it quickly these are standard plot commands with various options for you to label them and all that these are very specific you can go through these slides. Here are some of the results. So, just to give you an idea. So, Peclet number is 5 particle is starting from minus 0.5 you can see that the particle is located at the left side. So, it is equivalent to a random yeah gambler equivalent to a gambler starting with the bet point nearer to 0 less than half basically. You can see that as time progresses the distribution broadens it is almost like a delta function then it broadens and eventually the distribution goes to 0 because it will not be present anywhere it would have touched either got ruined or would have won. So, the game would have stopped anyway. So, you can see that subsequently the distribution flat turns out. This is just a specific show how the density varies at the center it has to come from the left side. So, it first rises and then of course, it gets depleted out by diffusion and convection. Then you have survival probability it starts with 1 then the survival probability virtually goes to 0 after some time because there is a strong Peclet number drift which drives it towards 1 wall plus there is also a diffusion. Here is the first contact time distribution or first passage time distribution we have discussed it earlier it would have a t to the power minus 3 by 2 kind of a behavior we had seen you can see that it rises and the distribution function has a long as a tail power lot tail and it is one of those distributions without higher moments also. This is numerically that we have seen analytically and here you have a numerical solution to that. Of course, the ones we mentioned where earlier for single absorbers. So, the actual functional forms could be different for the two absorbers we are not done it analytically. So, I correct myself, but this is the that obtained by numerical methods. Here is the winning probability, winning probability we can see that it as time increases winning probability definitely increases, but the maximum here he gets about 0.9 or so of course, because there is a strong bias. If you did not have bias for the same starting point you should have got much less if the it should be actually 25 percent or so, because it starts at 0.5 it would have been much less and that this program in fact, I would check that point also. So, to summarize these numerical exercises are indicative for you to say that simple programs can be written to understand stochastic phenomena and as and when you are faced with the real world problem we can develop on it and solve the problems by the basic equations that we have set up, interpretations that we have given and the models that we have discussed. Here I close these lectures on stochastic phenomena with that specifically scientific engineering applications in mind. Originally we plan to cover many more very interesting models. This will be now covered in the in future parts. We have in these lectures now learned how to develop probability density functions for various types of random walks and how we can develop a covering theories for random walk itself via the very well known Langevin dynamics approach. I wish my students very well in your career and in your future. The so called exams that will come from here will all be from within whatever has been taught simple questions and I hope that all that you have learnt here will serve in some way in enhancing your curiosity in interest in taking the problems in performing either research or applying in your in the chosen career that you have. Thank you all.