# Recursion: How can i program this expression?

i have the following expression:

Vt[EA_, V0_, Cm_, B_] := EA + (V0 - Cm)*B


For EA and Cm I have a list of the same length for each. B is a constant. For the first values of the lists the value for V0 is known (3500). For the other values of the lists Mathematica should use the respective outcome of the expression for V0 ( Vt[EA_, V0_, Cm_, B_]=V0 ) and so on. The outcome I want is a list with the same length as the other lists used in the computation +1. So the outcome should be equal to the use of the FoldList[] command. But for the use of the FoldList[] command iI have one expression that is too much. The work with Mathematica is relative new for me so I doen´t know how I can program this kind of recursion.

I hope someone can help me with this problem. Thank you very much

• FoldList[BerechnungAktieninvestment + (#1 - #2)*1.00003 &, 3500,ListeExposureAktien]. BerechnungAktieninvestment is the list for EA and ListeExposrueAktien ist the list for Cm. 1.00003 is the constant for B Jul 16 '16 at 12:33

Whenever the current computation depends upon the result of the previous step, think FoldList. FoldList is a fast and efficient function to use for those cases.

Let's look at this for three steps where the inputs are symbolic (tip: don't use upper case symbols, you may end up clashing with system symbols).

vt[ea_, v0_, cm_, b_] := ea + (v0 - cm)*b
ea = {ea1, ea2, ea3};
cm = {cm1, cm2, cm3};


In the application of FoldList we will create a list that consists of {eaN, cmN} pairs.

FoldList[vt[#2[], #1, #2[], b] &, v0,
Transpose[Join[{ea, cm}]]] // Column If you study the rows you can see that the v0 input to the current row is the value output from the previous computation.

Now apply it to a numerical example:

v0 = 3500;
ea = {10, 11, 12};
cm = {9, 10, 11};
b = 1.1;

FoldList[vt[#2[], #1, #2[], b] &, v0,
Transpose[Join[{ea, cm}]]]

(* {3500, 3850.1, 4235.11, 4658.52} *)

• Hello Jack LaVigne, Jul 16 '16 at 21:25
• The solution is great but i have the problem that i have a set of lists for ea and for cm like a set of 10000 and now i have the problem to create pairs of lists. Jul 16 '16 at 21:27
• i think i got it i have flatten both set of list and than transpoesed and joined it. it should work now thank you very much Jul 16 '16 at 21:44
RecurrenceTable[{vt[n + 1] == EA + (vt[n] - Cm)*B, vt == 3500}, vt, {n, 1, 10}]

• Thank you so if my lists have the legth of 720 i have to use {n, 1, 720} or {n, 1, 721}? Jul 16 '16 at 12:00
• Or gives Mathematica automaticly the length of 721 if i put in the lists for the EA and Cm? Jul 16 '16 at 12:06