0
$\begingroup$

I have tried to use RecurrenceTable to Solve a system of two differential equations. I look for having a sequence of the two variables n (population growth factor) and w (wages). I have provided initial conditions for n and w and the parameters I use. However, RecurrenTable does not give any results but runs for a very long time. I have tried to solve my system for the first iteration and I can obtain some results. As a consequence, I do not understand why RecurrenceTable can not solve it. You'll find my code below:

humanK[w_] := 2.9985119884257436`*^-7 (-4.297187`*^6 + 905580.` w + Sqrt[9.10441912969`*^11 + w (1.67789538072`*^12 + 8.200751364`*^11 w)]);earlyf[h_,    w_] := \[Delta]1/(\[Phi]1 (1 + \[Delta]1)) (1 - (\[Phi]1 \[Mu]1)/\ \[Delta]1 - h/w)
earlyf2[w_] := earlyf[humanK[w], w] /. param2 // FullSimplify;
param2 = {\[Alpha] -> 0.3, pi -> 0.9, \[Delta]1 -> 0.4, \[Mu]1 -> 0.1, \[Mu]2 -> 
0.32, \[Phi]2 -> 0.4, \[Beta] -> 0.6, \[Epsilon] -> 
0.65, \[Delta]2 -> 0.22, \[Phi]1 -> 2, A -> 2};
dynamics2 = RecurrenceTable[{n[t - 1] (1 - \[Phi]1 earlyf2[w[t]] + 1 + \[Epsilon] humanK[w[t - 1]] - pi \[Phi]2 latef[humanK[w[t - 1]]]) (w[t]/((1 - \[Alpha]) A))^(1/3) == w[t - 1]/n[t - 2] ((pi \[Beta] + \[Epsilon] humanK[w[t - 2]] + \[Phi]2 \[Mu]2)/(1 + \[Beta] + \[Delta]2) + ((1 - pi) \[Beta] (1 + \[Epsilon] humanK[w[t - 2]]))/(1 + \[Beta])) /. param2, n[t] == earlyf2[w[t]] + latef[humanK[w[t - 1]]] pi/n[t -1] /. param2, n[-1] == 0.01, n[-2] == 0.01, w[-1] == 2.2, w[-2] == 2}, {w, n}, {t, 0, 10}];
latef[h_] := (\[Delta]2 (1 + h) - \[Mu]2 \[Phi]2 (1 + \[Beta]))/(\[Phi]2 (1 + \[Beta] + \[Delta]2));

Could you help me and tell me why it does work? Do I made a mistake with the code? I have tried to look for some answers on StackExchange on previous questions, but I cannot solve the issue with my code. Thank you in advance,

$\endgroup$
6
  • 1
    $\begingroup$ I get the error RecurrenceTable::rtnc -- The number of constraints or initial conditions given, 4, should be the same as the total order of the system, 3. Maybe a typo in your code? Also, I guess these are difference equations, not differential equations. $\endgroup$
    – Chris K
    Commented Aug 21, 2022 at 13:36
  • $\begingroup$ Thanks Chris ! Indeed, I do not need to given initial conditions n[-1], you are right. Also, it is difference equations rather than differential. Nonetheless, even after correcting for initial conditions, mathematica runs but does not give any results. $\endgroup$
    – Natacha R
    Commented Aug 21, 2022 at 14:11
  • 1
    $\begingroup$ Your earlyf2 depends on earlyf, could you add the definition for the latter too? $\endgroup$ Commented Aug 21, 2022 at 14:40
  • $\begingroup$ Hi @მამუკა ჯიბლაძე, earlyf is written as follows: earlyf[h_, w_] := \[Delta]1/(\[Phi]1 (1 + \[Delta]1)) (1 - (\[Phi]1 \[Mu]1)/\ \[Delta]1 - h/w) Then, I obtain earlyf2 by plugging h=humanK[w]into earlfyf. $\endgroup$
    – Natacha R
    Commented Aug 22, 2022 at 6:18
  • $\begingroup$ Please modify the question accordingly. I mean, it should not throw the error mentioned in the first comment, and definition of earlyf must be present. By the way, the latter definition seems to contain a redundant `` $\endgroup$ Commented Aug 22, 2022 at 6:38

1 Answer 1

1
$\begingroup$

The question is still unclear but let me suggest a workaround anyway.

Set

humanK[w_] := 2.99851*10^-7 (-4.29719*10^6 + 905580 w 
    + Sqrt[9.10442*10^11 + w (1.6779*10^12 + 8.20075*10^11 w)]);
earlyf[h_,w_] := δ1/(φ1(1 + δ1))(1 - φ1 μ1/δ1 - h/w);
param2 = {α -> 0.3, pi -> 0.9, δ1 -> 0.4, μ1 -> 0.1, μ2 -> 0.32, φ2 -> 0.4, β -> 0.6, 
    ε -> 0.65, δ2 -> 0.22, φ1 -> 2, A -> 2};
earlyf2[w_] := earlyf[humanK[w], w] /. param2 // FullSimplify;
latef[h_] := (δ2(1 + h) - μ2 φ2 (1 + β))/(φ2 (1 + β + δ2));

eqs =
 {
   n[t - 1](1 - φ1 earlyf2[w[t]] + 1 + ε humanK[w[t - 1]]
     - pi φ2 latef[humanK[w[t - 1]]]) (w[t]/((1 - α) A))^(1/3) == 
    w[t - 1]/n[t - 2] ((pi β + ε humanK[w[t - 2]] + φ2 μ2)/(1 + β + δ2)
     + ((1 - pi) β (1 + ε humanK[w[t - 2]]))/(1 + β)), 
   n[t] == earlyf2[w[t]] + latef[humanK[w[t - 1]]] pi/n[t - 1]
 } /. param2

out = {n[-2] -> .01, w[-2] -> 2, n[-1] -> .01,  w[-1] -> 2.2}

Then you can just iterate:

Do[
   out = out \[Union] First@Solve[eqs[[1]] //. t -> k //. out];
   out = out \[Union] First@Solve[eqs[[2]] //. t -> k //. out],
  {k, 0, 10}
]

The result

TableForm[Prepend[Table[{k, n[k], w[k]} /. out, {k, -2, 10}], {t, n[t], w[t]}]]

is this:

|t  |n[t]        |w[t]         |
|---|------------|-------------|
|-2 |0.01        |2            |
|-1 |0.01        |2.2          |
|0  |6.95136     |1.30852*10^11|
|1  |2.78041*10^9|17677.8      |
|2  |-0.00520365 |152.063      |
|3  |-4243.91    |0.00617452   |
|4  |0.717483    |0.198168     |
|5  |0.440254    |0.188684     |
|6  |0.202424    |0.198426     |
|7  |-0.481408   |0.22558      |
|8  |1.36723     |0.156763     |
|9  |0.594717    |0.186253     |
|10 |0.358851    |0.192167     |

Note however that I used your n[-1] -> .01, and later in a comment you said you actually do not want to fix n[-1]. If this is the case, then you should do

out = {n[-2] -> .01, w[-2] -> 2, w[-1] -> 2.2}

and

Do[
 out = out \[Union] First@Solve[eqs[[2]] //. t -> k - 1 //. out];
 out = out \[Union] First@Solve[eqs[[1]] //. t -> k //. out],
 {k, 0, 11}
];

the result is quite different:

|t  |n[t]      |w[t]   |
|---|----------|-------|
|-2 |0.01      |2      |    
|-1 |4.06751   |2.2    |
|0  |0.0110253 |1944.85|
|1  |26031.9   |65338. |
|2  |0.365511  |152.586|
|3  |60.9552   |144.29 |
|4  |0.340298  |142.625|
|5  |61.1481   |149.287|
|6  |0.351272  |143.464|
|7  |59.5907   |148.983|
|8  |0.359834  |143.405|
|9  |58.1481   |148.834|
|10 |0.36851   |143.394|
$\endgroup$
3
  • $\begingroup$ Thanks a lot @ მამუკა ჯიბლაძე that's great! I can run your code and obtain the same results. As you righfully noticed, I have chosen n[-1]=1eventually. How can I exctract a list of wand nfrom the Table? Should I use List or something likewise? $\endgroup$
    – Natacha R
    Commented Aug 22, 2022 at 14:19
  • $\begingroup$ @NatachaR Just do Table[{k, n[k], w[k]} /. out, {k, -2, 10}], this will give you the list of the n and w values $\endgroup$ Commented Aug 22, 2022 at 15:08
  • $\begingroup$ Thanks a lot again @მამუკა ჯიბლაძე ! It seems to work now. All the best, $\endgroup$
    – Natacha R
    Commented Aug 22, 2022 at 16:08

Your Answer

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

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