Generalized Boundary Problem for 
One-Dimensional Random Walks:   David K. Neal

p=.40;
q=1-p;
StepsUp=h=3.2;
StepsDown=k=2.4;
StartingHeight=m=6;
UpperBoundary=n=10;

trials=300;
Do[x[i,0]=m, {i,1,trials}];

Do[j=0;
   While[0 < x[i,j] < n,
        x[i,j+1] = If[Random[] < p,
                     x[i,j]+h,
                     x[i,j]-k];
        j++];
   t[i] = j;
   u[i] = If[x[i,t[i]] >= n,
            1, 0],
   {i, 1, trials}]

Do[ListPlot[Table[{j,x[i,j]}, {j,0,t[i]}],
		PlotJoined -> True,
		AxesOrigin -> {0,0}],
{i,1,2}]

p1 = ProportiontoHitUpper =
   N[Sum[u[i], {i,1,trials}] / trials]

SampleMeanTime = N[Sum[t[i], {i,1,trials}] / trials]

RealProb =
If[p==.5,
  m/n,
  (1-(q/p)^m)/(1-(q/p)^n)]

AveTime =
If[p==.5,
  m(n-m),
  n/(p-q)*(1-(q/p)^m)/(1-(q/p)^n) - m/(p-q)]

<<Statistics`ConfidenceIntervals`

c=.95;

ProbCI =
N[NormalCI[p1,.5/Sqrt[trials],
          ConfidenceLevel -> c]]

Do[Do[j=0;
     While[0 < x[i,j] < n,
          x[i,j+1]=If[Random[]<p,
                     x[i,j]+h,
                     x[i,j]-k];
          j++];
     t[i] = j,
     {i,1,100}];
  b[s] = N[Sum[t[i],{ i,1,100}] / 100],
{s,1,30}]

TimeData = Table[b[s], {s,1,30}]

mu = N[Mean[TimeData]];
sd = N[StandardDeviation[TimeData]];

TimeCI = N[NormalCI[mu, sd/Sqrt[30],
                   ConfidenceLevel -> c]]

Clear[m];
p = .40;
q = 1-p;
StepsUp = h = 3;
StepsDown = k = 2;
UpperBoundary = n = 10;

a = IdentityMatrix[n-1];
Do[a[[i,i-k]] = -q, {i,k+1,n-1}];
Do[a[[i,i+h]] = -p, {i,1,n-1-h}];

a

b = Table[If[i <= n-h-1, 0, p],
         {i, 1, n-1}, {j,1,1}]

Soln = LinearSolve[a, b];

Table[{m,Soln[[m]]}, {m,1,n-1}]

b2 = Table[If[i <= k, q, If[i<=n-h-1,0,p]],
          {i,1,n-1}, {j,1,1}]

Soln2 = LinearSolve[a, b2]

b3 = Table[1, {i,1,n-1}, {j,1,1}]

Soln3=LinearSolve[a, b3];

Table[{m,Soln3[[m]]},{m,1,n-1}]

Table[{m,If[p==.5,m/n,(1-(q/p)^m)/(1-(q/p)^n)]},
{m,1,n-1}]

Table[{m,If[p==.5,m(n-m),
n/(p-q)*(1-(q/p)^m)/(1-(q/p)^n) - m/(p-q)]},{m,1,n-1}]