0
$\begingroup$

I had asked this question at an initial level before; thank you to all with your suggestions. Now this problem is getting complicated and I am unable to figure it out. There is a 10x10 matrix of zeros (call it tab). The first row of tab needs to be replaced with the first row of tab1 (3x10 matrix)

tab1= {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, {3, 
  3, 3, 3, 3, 3, 3, 3, 3, 3}}

rnorms is a matrix 10x10 of random normal variables: you can define it whatever way you want

The issue is that subsequent rows of tab depend on the previous rows of tab given

tab[[1]]=tab1[[1]]: alpha=.011, sigma=0.127
tab[[2]]=1.011*tab[[1]]+0.127*rnorms[[1]]*tab[[1]]
tab[[3]]=1.011*tab[[2]]+0.127*rnorms[[1]]*tab[[2]]

and so on. For each value of tab1[[1]], I will get a matrix of tab; so the matrix should be repeated 3 times. For each time, I want to store the sum of the columns of the matrix. The resulting matrix (of sums of columns) should have dimensions 3x10.

For getting the matrix tab to be repeated 3 times (based on the values of tab1), I have tried

(NestList[{(1 + alpha) #[[1]] + sigma rnorms[[#[[2]]]] #[[1]], #[[2]] + 1} &, 
    {#, 1}, 9] & /@ tabl) 

which is giving me the wrong result (I have tried to compute each matrix manually by replacing the first row of tab). More so, I get

{{{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 1}, 
 {{1.09703, 1.0021, 1.04791, 1.10641, 0.836817, 0.950917, 1.18247, 0.941276, 
    1.07136, 1.01164}, 2},.........
{{{2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, 1}, 
 {{2.19405, 2.00421, 2.09581, 2.21281, 1.67363, 1.90183, 2.36493,
    1.88255, 2.14271, 2.02327}, 2}, 
 {{2.21106, 1.95679, 2.35947, 2.00476, 1.31318, 2.25086, 1.93982,
    1.83749, 2.5103, 1.896}, 3},.........

and so on.

The above command of NestList is not taking each row of rnorms and multiplying it with the given row of tab1[[1]] and then computing the whole matrix each time. I would appreciate any help.

$\endgroup$
1
$\begingroup$

Once again I find it difficult to understand what you are asking, but my best take on your question is that you are looking for

Module[{rnrms = {1, 2, 3}, f, sums},
  With[{alpha = .011, sigma = 0.127},
    f[1, j_] := rnrms[[j]];
    f[i_, j_] := (f[i, j] = (1 + alpha + sigma rnrms[[j]]) f[i - 1, j])]; 
  sums = Table[Total[Table[f[i, j], {j, Length @ rnrms}]], {i, Length @ rnrms}];
  ConstantArray[#, 10] & /@ sums]
{{6, 6, 6, 6, 6, 6, 6, 6, 6, 6}, 
 {7.844, 7.844, 7.844, 7.844, 7.844, 7.844, 7.844, 7.844, 7.844, 7.844}, 
 {10.3085, 10.3085, 10.3085, 10.3085, 10.3085, 10.3085, 10.3085, 10.3085, 10.3085, 10.3085}} 

As with your previous question, I calculate the sums for just one column, and replicate the sums 10 times.

$\endgroup$
  • 1
    $\begingroup$ Another possibility: ArrayPad[List /@ sums, {{0, 0}, {0, 9}}, "Fixed"]. $\endgroup$ – J. M. will be back soon Dec 16 '15 at 1:36
  • 2
    $\begingroup$ @J.M. That's really nifty, but given the OP demonstrated level of Mathematic savvy, I think mapping ConstantArray will be more digestible. $\endgroup$ – m_goldberg Dec 16 '15 at 1:59
  • $\begingroup$ Sorry to bother you again, I have pnew[i_] := For[tab[[1]] = tabn[[i]]; j = 2, j <= 6, j++, tab = ReplacePart[tab, j -> (1 + al)*tab[[j - 1]] + sigma*epsilon[[j - 1]]*tab[[j - 1]]]] $\endgroup$ – Supratim Das Gupta Dec 18 '15 at 5:34
  • $\begingroup$ I wanted to ask a specific short question but let me open a new question $\endgroup$ – Supratim Das Gupta Dec 18 '15 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.