I have generated two time series, S[t]
and P[t]
as follows:
In[2990]:= Table[S[t], {t, 1, 50}]
Out[2990]= {0.5, 0.5, 2.253, 2.7614, 2.87762, 4.05318, 5.03183, 5.42801, 6.32663,
7.43033, 8.14412, 8.98434, 10.0983, 11.0536, 11.9744, 13.0988, 14.2194, 15.2811,
16.4588, 17.7028, 18.9201, 20.1964, 21.5544, 22.9261, 24.3338, 25.8165, 27.3415,
28.9023, 30.5282, 32.2123, 33.9413, 35.7309, 37.5859, 39.4971, 41.4699, 43.5124,
45.6209, 47.7963, 50.0454, 52.3689, 54.7668, 57.2436, 59.8024, 62.4438, 65.1712,
67.988, 70.8963, 73.8987, 76.9988, 80.1996}
In[3057]:= Table[P[t], {t, 1, 50}]
Out[3057]= {0.75, 0.75, 0.75, 0.75, 2.22, 2.26635, 2.31409, 4.72832, 5.47929, 5.71359,
7.38173, 8.77145, 9.38649, 10.687, 12.2584, 13.3072, 14.5348, 16.1313, 17.5145,
18.8577, 20.4782, 22.0947, 23.6365, 25.3391, 27.1332, 28.8952, 30.7413, 32.7011,
34.6829, 36.7181, 38.8585, 41.0603, 43.3149, 45.6623, 48.0927, 50.5888, 53.1718,
55.8482, 58.6059, 61.4525, 64.3987, 67.44, 70.5779, 73.8214, 77.1718, 80.6293,
84.2004, 87.8892, 91.6969, 95.6281}
Now, these two time series are related to each other by a lag, L[t]
. Thus, S[t]==P[t-L[t]]
. Time series of L[t]
is not known and I have to find it from given S[t]
and P[t]
.
My code for this is:
Do[{Do[If[S[t] > P[i], k = i], {i, 1, t}],Print[t-k]},{t,5,50}]
The list of numbers printed out, i.e. t-k
, is exactly what I expected. So I would like to define L[t_] := t - k
. But if I substitute this for Print[t-k]
in the code and Print
the resulting list of numbers, I get a different result. Is there any way to define this function?