# How to solve the recursion equation that include the uncertain value i in it?

I write the following code of a recursion equation, but it can not work correctly.

RSolve[{
a[0]==(1-p)a[n],
For[i=1,i<=n-1,i++,a[i]==p a[n-i+1]+(1-p)a[n-i]],
a[n]==a[0]+p a[1],
Sum[a[k],{k,0,n}]==1},
a[n],n]

-

First of all, your problem is not a recursion equation.

It is more reasonable to consider it as a system of simultaneous equations.

The main point is that your problem has the fixed number of a[n].

Try to manipulate n number of equations you described.

You can get

a[0]== a[0]

a[1]== a[2]== ... == a[n-1] == a[n] == a[0]/(1-p)

Thus, Sum[a[k],{k,0,n}]==(n-p)a[0]/(1-p) == 1 Finally, a[0]== (1-p)/(n-p).

-