If I wanted to generate a sequence that follows the pattern
$$x_{n}=x_{n-1}+\dfrac{1}{2}\left(\sqrt{1-y_{n-1}\ ^{2}}-x_{n-1}\right)\\ y_{n}=y_{n-1}+\dfrac{1}{2}\left(\sqrt{1-x_{n}\ ^{2}}-y_{n-1}\right)$$
rather than writing the whole thing out:
x0 = N[0 + 1/2 (Sqrt[1 - 0^2] - 0)];
y0 = N[0 + 1/2 (Sqrt[1 - x0^2] - 0)];
x1 = N[x0 + 1/2 (Sqrt[1 - y0^2] - x0)];
y1 = N[y0 + 1/2 (Sqrt[1 - x1^2] - y0)];
... etc. What is the best way to do it?
Answer
The previous answers correspond to the recursive model of the form $$[x_n,y_n]=[f(x_{n-1},y_{n-1}),g(x_{n-1},y_{n-1})]$$. However, the state-space model of the question is of the form \begin{align} [x_n,y_n]&=[f(x_{n-1},y_{n-1}),g(x_{n-1},y_{n-1},x_n)]\\ &=[f(x_{n-1},y_{n-1}),g(x_{n-1},y_{n-1},f(x_{n-1},y_{n-1}))] \end{align} The latter equation is the correct form that should be applied with the methods proposed by the previous answers. Another method could be to use NestList
h[{x_, y_}] := {x + 1/2 (Sqrt[1 - y^2] - x),
y + 1/2 (Sqrt[1 - (x + 1/2 (Sqrt[1 - y^2] - x))^2] - y)};
x0 = N[0 + 1/2 (Sqrt[1 - 0^2] - 0)];
y0 = N[0 + 1/2 (Sqrt[1 - x0^2] - 0)];
NestList[h, {x0, y0}, 10]
{{0.5, 0.433013}, {0.700694, 0.573237}, {0.760042,
0.611556}, {0.775621, 0.621377}, {0.779567, 0.623848}, {0.780556,
0.624467}, {0.780804, 0.624622}, {0.780865, 0.624661}, {0.780881,
0.62467}, {0.780885, 0.624673}, {0.780886, 0.624673}}
Comments
Post a Comment