I have lensp=101; pid=0.5212; qid=1-pid; e1=0;
Let's say I have a matrix such as newp = Table[e1, {i, lensp}, {j, lensp}];
I am trying to replace the elements of the matrix such that for each row i
, the Min[i+1,lensp]
th column=pid
, and the Max[i-1,1]
th column=1-pid
. So each row should have two non-zero elements and the rest are zeros. [The Matlab code is newp(i,min(i+1,lensp))=pid
and correspondingly]. I have tried many times in Mathematica but without success. I have tried
For[i = 1, i <= lensp, i++,
For[j = 1, j <= lensp, j++,
newp = ReplacePart[newp, newp[[i, Min[i + 1, lensp]]] = pid,
newp[[i, Max[i - 1, 1]] ] = qid]
]
]
but it does not work.