Random walking on two-dimensional finite lattice points

Source: Internet
Author: User

For a 10x10 grid, from the center of the grid, the probability of travelling in four directions is 1/4, and if you encounter a boundary (hitting a wall) during the walk, then reject this step. So the resulting distributions are evenly distributed? The result is a uniform distribution. We can use the Metroplis sample to explain. First of all the sampling process to meet the meticulous balance, because we are in the wall when the reject, the implicit Markov transfer matrix is obviously the various state traversal, so the final uniform distribution is not surprising.

% Random_walk bounded 001% 2 dimensional random walk on a 100x100 latticefprintf (' Random walk on a bounded lattice\n ');% l Attice sizelsize = 10;lattice = Zeros (lsize); fprintf (' lattice size =%d\n ', lsize);% number of random walksmaxn = 1000000; fprintf (' number of random walks =%d\n ', MAXN);% start from the centerx0 = Floor (LSIZE/2); y0 = Floor (LSIZE/2); for I=1:MAXN    x1 = x0 + Randi (2) *2-3;    Y1 = y0 + Randi (2) *2-3;    If x1<=0        x1 = 1;    End    if x1>lsize        x1 = lsize;    End    If y1<=0        y1 = 1;    End    If y1>lsize        y1 = lsize;    End    Lattice (x1, y1) = Lattice (x1,y1) + 1;    x0 = x1;    y0 = Y1;endmean_value = mean (reshape (lattice, [lsize*lsize,1])); std_value = STD (reshape (lattice, [lsize*lsize,1])); fprintf (' Mean =%f std =%g\n ', Mean_value, Std_value); fprintf (' Std/mean =%f\n ', std_value/mean_value);

Partial output results

>> Rand_walk_boundedrandom Walk on a bounded latticelattice size = 10Number of random walks = 1000000Mean = 10000.00 0000 std = 117.798std/mean = 0.011780

Clumsy to draw a probability map (ignoring the colorful colors, I do not know how to get down @[email protected]), pay attention to the scale of the z-axis.

Random walking on two-dimensional finite lattice points

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.