MATLAB: Adding Bias To Random Walk biasprobabilityrandom walk How would add a bias or probability of 34%, 22%, 22%, and 22% for each of the four directions in the attached random walk code? Best Answer you can make a step & bias vector:stepCoordinates = [1,0;0,1;-1,0;0,-1];% this creates the bias to the northbias = [ones(1, 34), repmat([2 3 4], 1, (100-34)/3)];then when you generate the actual steps in your loop use this instead of what you had:stepBiasIndex = randi(100, 1, numberOfSteps); stepCoordIndex = bias(stepBiasIndex); delta = stepCoordinates(stepCoordIndex,:); if continuousSteps signOfStep = sign(delta); plusminusRandSign = [-1 1]; indicesWithSignZero = signOfStep == 0; signOfStep(indicesWithSignZero) = plusminusRandSign(randi(2, size(signOfStep(indicesWithSignZero)))); delta = delta - signOfStep.*rand(numberOfSteps, 2); end deltax = delta(:,2)'; deltay = delta(:,1)'; You can vectorize the rest of it but you said it does what you want so i didn't touch anything elseIn this specific solution the bias is only in percentage because the bias vector is a 1x100 vectorso if you want to be more specific about it you can make it a 1x1000 for promils or 1x10000 for higher precision...I attached the edited file Related SolutionsMATLAB: Random Walk on 2D Modification dd = randi(4) for ss = 1:500 rr = rand; if rr < 1/4 dd = 1+mod(dd,4) %next higher direction elseif rr < 1/2 dd = 1+mod(dd-2,4) %next lower direction end % 50 percent stays same direction if dd==1 yy=yy+1; %north elseif dd==2 xx=xx+1; %east elseif dd==3 yy=yy-1; %south else xx=xx-1; %west end plot here probably end MATLAB: I am trying to simulate a biased 2d random walk in a 100 x 100 unit domain and I can’t get the particles to walk one at a time and stick once they have either reached the bottom row or an occupied square. I'm pretty sure that one of my attached random walk simulations does something like that - quit when it reaches some boundary. Try them. Related QuestionAircraft deplaning and centre of gravityI have to do a single index for the NorthSelf avoiding random walkHow to find the direction of the moving object in a sequence of framesProblem with find function
Best Answer