# Finding a vector many times

I have a vector matrix of profits say

prof= {{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}};


I have a "terminal value vector" as

vt={1,2,3,4,5};


and a constant

npva=2;


Now the problem is to find vt at each preceding step of $v(t - 1), v(t - 2)...v(0)$ taking the Maximum of (the average of the vt + profits at each time t, npva) and then putting the resulting max as the vt of the following step.

So given the average of vt=3 (a scalar), I add prof[] so that I get {8,8,8,8,8} and then take the Max of EACH ELEMENT OF THIS VECTOR compared to npva. This gives $v(t-1)=\{8,8,8,8,8\}$. So for the next step, I take the average of $v(t-1)$, but add prof[], and then taking the Max compared with npva, I get the vector $v(t-2)$ and so on..

I tried to use For first but it doesn't work. I think FoldList can be used, but I do not know how to pull in each row from another matrix when the process is repeated. Above all, how can you incorporate the Max that I want in the command? Any help would be greatly appreciated.

• Please include the code you have developed for this problem. – bbgodfrey Feb 2 '16 at 23:20

Combine your vt and prof lists together.

 list = {vt, prof}


The function findVt gives the next combined list of vt and prof. Form prof it drops the last element.

findVt[comList_] :=
Module[{npva = 2, profList, profLen, mean, vtList, list1, list2},
vtList = First@comList;
profList = Last@comList;
profLen = Length[profList];
mean = Mean[vtList];
list1 = Last@profList + mean;
list2 = Max[#, npva] & /@ list1;
profList = Drop[profList, {profLen}];
{list2, profList}
]


Lets check the function

 findVt[list]

(*{{8, 8, 8, 8, 8}, {{1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {3, 3, 3, 3, 3}, {4, 4, 4, 4,4}}}*)


So it gives the expected result. Now we can use NestWhileList with the condition on the length of the prof list.

 res = NestWhileList[findVt, list, Length[#[]] >= 1 &];


res will store the combined list including the prof list at each iteration. Just the vt results are as follows.

 res[[All, 1]]

(*{{1, 2, 3, 4, 5}, {8, 8, 8, 8, 8}, {12, 12, 12, 12, 12}, {15, 15, 15, 15, 15}, {17, 17, 17, 17, 17}, {18, 18, 18, 18, 18}}*)

• Thank you very much for your help. I have tried the code with success. Sincerely. – Supratim Das Gupta Feb 3 '16 at 22:56