random_walk_2d_avoid_simulation, a MATLAB code which simulates a self-avoiding random walk in a 2D region.
A random self-avoiding walk of length STEP_NUM in 2D can be generated by generating a random walk in 2D and "hoping" it doesn't intersect itself. If the next step would cause an intersection, then the generation is terminated prematurely; to ensure that the self-avoiding random walks are selected uniformly, we have to just keep trying random walks this way and "hoping".
The code RANDOM_WALK_2D_AVOID_PLOT plots the trajectories of one or more self-avoiding random walks. The user gives a desired length STEP_NUM, and the code generates a random walk that either reaches STEP_NUM without self-intersection, or is terminated early to avoid intersection.
The code RANDOM_WALK_2D_AVOID_SIMULATION plots averaged data for any number of self-avoiding random walks that each try to achieve the same number of steps. The data plotted includes the number of steps each walk reached before termination, and a least squares fit to the distance versus number of steps.
random_walk_2d_avoid_plot ( step_num, walk_num )where
random_walk_2d_avoid_simulation ( step_num, walk_num )where
The information on this web page is distributed under the MIT license.
random_walk_2d_avoid_simulation is available in a MATLAB version and an Octave version and a Python version.
random_walk_2d_avoid_simulation_test
matlab_simulation, a MATLAB code which uses simulation to study card games, contests, and other processes which have a random element. Usually, the purpose is to try to predict the average behavior of the system over many trials.