I am trying to replace 1s row of matrix d iteratively from right by multiplying last element in 1st row with (1-int*dt) to generate 2nd last element. The replacement continues till I reach the 1st element of the row using code below. Can anybody help to let me know where I am going wrong. The code doesnt give error but gives out initial element without doing replacement. I am trying to find out a efficient way to replace elements of the matrix recursively based on certain rules/function. Is ReplacePart best to use or there is other way?
elemOperate[int_, dt_, nas_, nts_] :=
Module[{d},
d = ConstantArray[2, {nas + 1, nts}];
For[j = nts, j--,
d =
ReplacePart[d, {1, j_ - 1} :> (1 - int*dt)*d[[1, j]]]
];
Grid[d]
]
elemOperate[0.01, 0.1, 4, 4]
generates following output:
{ {"2", "2", "2", "2"}, {"2", "2", "2", "2"}, {"2", "2", "2", "2"}, {"2", "2", "2", "2"}, {"2", "2", "2", "2"} }