1
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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 $\endgroup$
    – user41673
    Jul 16, 2016 at 12:33

2 Answers 2

2
$\begingroup$

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]], #1, #2[[2]], b] &, v0,
    Transpose[Join[{ea, cm}]]] // Column

Mathematica graphics

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]], #1, #2[[2]], b] &, v0, 
 Transpose[Join[{ea, cm}]]]

(* {3500, 3850.1, 4235.11, 4658.52} *)
$\endgroup$
3
  • $\begingroup$ Hello Jack LaVigne, $\endgroup$
    – user41673
    Jul 16, 2016 at 21:25
  • $\begingroup$ 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. $\endgroup$
    – user41673
    Jul 16, 2016 at 21:27
  • $\begingroup$ 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 $\endgroup$
    – user41673
    Jul 16, 2016 at 21:44
1
$\begingroup$
RecurrenceTable[{vt[n + 1] == EA + (vt[n] - Cm)*B, vt[1] == 3500}, vt, {n, 1, 10}]
$\endgroup$
2
  • $\begingroup$ Thank you so if my lists have the legth of 720 i have to use {n, 1, 720} or {n, 1, 721}? $\endgroup$
    – user41673
    Jul 16, 2016 at 12:00
  • $\begingroup$ Or gives Mathematica automaticly the length of 721 if i put in the lists for the EA and Cm? $\endgroup$
    – user41673
    Jul 16, 2016 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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