In a onedimensional random walk the position x of a walker i
     In a one-dimensional random walk the position x of a walker is computed by  x_j = x_j + s  where s is a random number. Write a program that calculates the number of steps required for the walker to reach a boundary x = plusminus B. Use MATLAB\'s built-in function randn(1, 1) to calculate s. Run the program 100 times (by using a loop) and calculate the average number of steps when B = 10.  
  
  Solution
Writing a function in Matlab
 
function ans = Average()
B = 10;
x = 0;
for a = 1:100
s = randn(1,1);
   x = x + B;
    ans = ans +1;
If x >= B
x = 0;
    break;
ans = ans/100;
end
 
 
 Thanks, Let me know if there is any concern

