# Replacing the first row of one matrix with a row of another matrix and then proceeding [closed]

I have

pnew[i_] := For[tab[] = tabn[[i]]; j = 2,
j <= 6, j++,
tab = ReplacePart[tab, j -> (1 + al) x tab[[j - 1]] + sigma x epsilon[[j - 1]]*tab[[j - 1]]]]


where tab is a 5x5 matrix of zeros,

epsilon={{1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {3, 3, 3, 3, 3},
{4, 4, 4, 4, 4}, {5, 5, 5, 5, 5}}


and

tabn={{1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {3, 3, 3, 3, 3}}


al and sigma are constants: al = 0.5; sigma = 0.1;

The question is that I want to find a tab matrix each time by having the first row replaced by one of the rows of tabn. In this example, I would get the tab matrix 3 times and I want one big matrix with all 3 realizations of tab.

I have tried tab /@ pnew and then evaluated tab...but this gives me only one (the first) realization of tab. I have tried tab # &/@[pnew[i],{i,1,3}] but it doesn't work. Any help would be appreciated.

• What is x ? ... – Dr. belisarius Dec 18 '15 at 6:30
• I am sorry I meant x to be the multiplication sign – Supratim Das Gupta Dec 18 '15 at 17:35
• well, not in Mathematica – Dr. belisarius Dec 18 '15 at 17:39

Initializing the tab matrix

tab = ConstantArray[0, {5, 5}];


Defining the rules for second row onwards

rule[j_] := j -> (1 + al) * tab[[j - 1]] + sigma*epsilon[[j - 1]]*tab[[j - 1]]


bigMat stores the full set of results

bigMat = Table[
tab = ReplacePart[tab, {1 -> tabn[[i]]}];
res[i] = Last@Table[
tab = ReplacePart[tab, {rule[j]}], {j, 2, 6}
],{i, 1, 3}
]


The individual matrices are stored in res[i]

• Hello, thank you very much. I would try your suggestion. – Supratim Das Gupta Dec 18 '15 at 17:32