# While-Loop Linear Projection

I'm would like to do a linear progression for a recursive relation of a consumption function. Combining my program skills and my sparse knowledge of mathematica, I was thinking about doing it in a while-loop as follows:

 While[\[CapitalDelta]Cp < 1,
Cp = 0.4 \[CapitalDelta]Y +
0.407 (0.9 Subscript[Yl, -1] + 0.1 Subscript[Wl, -1] - Subscript[
Cp, -1]) + Subscript[Cp, -1];
\[CapitalDelta]Cp = Cp - Subscript[Cp, -1];
W = Subscript[Wl, -1] + (\[CapitalDelta]Y + Subscript[Yl, -1]) - Cp;
Subscript[Wl, -1] = W;
Subscript[Cp, -1] = Cp;
]


Though, it doesn't work.

EDIT: Clearifying----

I have to functions, one that determines consumption (Cp) and one that determines the fortune (Wp). They are recursive in that I need to determine the consumption before I can determine the fortune.

$$Cp=0.4\Delta Y+0.407(0.9Y_{-1}+0.1Wp_{-1}-Cp_{-1})\\ Wp=Wp_{-1}+Y-Cp$$

The symbol $_{-1}$ states that the data are lagged meaning that it is last years value.

Initially I append the following data to the variables in order for the loop to start, since I would like to project the value of Cp and Wp ten year ahead.

$$Y_{-1}=1\\ Wp_{-1}=1\\ Cp_{-1}=1\\ \Delta Y=1\\$$

Then I would like to make a loop that iterates through the functions 10 times, whereas they after each iteration automatically assign the newly calculated value to the lagged variables, being:

$$Y_{-1}=Y\\ Wp_{-1}=Wp\\ \vdots$$

I would like for $\Delta Y$ to increment by 1% each year automatically as well. How is this possible? Please ask if the question is still unclear.

OBJECTIVE

The purpose of this whole head-ache of mine is to make a prototype of a consumption model of a given society. Therefore, I would like to be able to write the acquired data in a graph, with the percentage of change in the different variables on the Y-axis and the years of projection on the X-axis (i.e. 1, 2, 3, ... 10).

In short, the consumption equation is defined as: $$dlog(C)=0.4 dlog(Y)+0.407(log(Y_{-1}^{0.9} W_{-1}^{0.1})-0.200 log(C_{-1}))+0.011$$ Whilst the fortune equation corresponds to: $$W=W_{-1}+Y+C$$

The reason I've used the above annotation is because I wanted to linearize the consumption equation with the purpose of placing both of the equation in a matrix system (correspondingly $dlog(C)=log(C)-log(C_1)=\Delta C_l,\text{where}C_l=log(C)$). Firstly, though, I wanted to get it to work.

The initial values of the lagged variables are set to 1. In my first example I left out the parameters to simplify the projection. Then, when the system worked, I wanted to add them. Hope it clarifies it well enough.

OBJECTIVE END

----EDIT END

How can I solve this?

-
Be careful with Subscript[Cp,-1] since Cp has a value, lets say for example 10.1 then what you are really doing is Subscript[10.1, -1] which I doubt is what you want. Can you describe what you want mathematically, ie the recurrence relation you actually want to solve, and example initial values. Then it will be easy to help you get the correct code. –  Gabriel Dec 17 '12 at 13:39
note that Attributes@Subscript is NHoldRest so c = 3; Subscript[c, 1] // Trace gives {{c,3},Subscript[3, 1]} which, as Gabriel says, is probably not what you intended. –  acl Dec 17 '12 at 13:57
Please see my elaboration. –  Frederik Brinck Jensen Dec 17 '12 at 14:42
I might have missed it, but what is the update rule for Y and should C in Wp have a lagged subscript? –  image_doctor Dec 17 '12 at 15:21
The update rule for Y is a 1% increment each year. C in Wp should have been Cp (I missed out the p – it has been corrected). –  Frederik Brinck Jensen Dec 17 '12 at 23:42

This is quite unclear to me. It looks like you are trying to solve a system of (linear) recurrence equations. That can be done as below. But you have inconsistencies. Your "deltay" is stated to be 1, but it also seems to denote y[p]-y[p-1], and moreover should increase by 1/100 each year. This is overdetermined (cannot meet all conditions).You also have fixed values of 1 for your lagged fortune and consumption variables, but the equations imply that they are not in fact fixed. Very confusing. I'm taking a guess below as to what it is you actually want.

eqns = {consump[p] ==
4/10*(yy[p] - yy[p - 1]) +
407/1000*(9/10*yy[p - 1] + 1/10*fortune[p - 1] - consump[p - 1]),
fortune[p] == fortune[p - 1] + yy[p] - consump[p],
yy[p] == 101/100*yy[p - 1]};
inits = {yy[0] == 1, consump[0] == 1, fortune[0] == 1};

In[7]:= sol = RSolve[Join[eqns, inits], {consump[p], fortune[p], yy[p]}, p]

(* {{consump[p] -> (1/10685239172533)
2^(-1 - 5 p)
5^(-4 p) (866193113449 2^(2 + 3 p) 5^(1 + 2 p) 101^p +
2023308038043 (5523 - Sqrt[193303529])^p +
958549081 Sqrt[193303529] (5523 - Sqrt[193303529])^p +
2023308038043 (5523 + Sqrt[193303529])^p -
958549081 Sqrt[193303529] (5523 + Sqrt[193303529])^p),
fortune[p] -> (1/10685239172533)
2^(-5 p) 5^(-4 p) (2023308038043 2^(3 p) 5^(2 p) 101^(1 + p) -
96834436334905 (5523 - Sqrt[193303529])^p +
6801810845 Sqrt[193303529] (5523 - Sqrt[193303529])^p -
96834436334905 (5523 + Sqrt[193303529])^p -
6801810845 Sqrt[193303529] (5523 + Sqrt[193303529])^p),
yy[p] -> (101/100)^p}} *)

-

I'm offering this in the interim until a few more details are resolved.

Essentially you supply Nest with a state vector consisting of {Y,W,C,dY}, here it is {1,1,1,1}, for the first year and then supply a function to update the state vector as many times as required, here it is 10.

NestList[With[{dY = #[[4]] + 0.1}, {#[[1]], #[[2]] + #[[1]] -1,
0.4 dY + 0.407 (0.9 #[[1]] + 0.1 #[[2]] - #[[3]]), dY}] &, {1,1, 1, 1}, 10]


{{1, 1, 1, 1}, {1, 1, 0.44, 1.1}, {1, 1, 0.70792, 1.2}, {1, 1, 0.638877, 1.3}, {1, 1, 0.706977, 1.4}, {1, 1, 0.71926, 1.5}, {1, 1, 0.754261, 1.6}, {1, 1, 0.780016, 1.7}, {1, 1, 0.809534, 1.8}, {1, 1, 0.83752, 1.9}, {1, 1, 0.866129, 2.}}

-