4
$\begingroup$

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?

$\endgroup$

5 Answers 5

11
$\begingroup$

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}}
$\endgroup$
1
  • $\begingroup$ You are right indeed, nicely spotted :) $\endgroup$
    – C. E.
    Commented Oct 12, 2014 at 21:23
6
$\begingroup$

In an earlier edit, I had misread one of the subscripts in the y equation (thanks to Stelios for pointing this out). Here is the corrected version:

x[n_] := x[n] = x[n - 1] + 1/2 (Sqrt[1 - y[n - 1]^2] - x[n - 1]);
y[n_] := y[n] = y[n - 1] + 1/2 (Sqrt[1 - x[n]^2] - y[n - 1]);
x[0] = 0.5;
y[0] =  1/2 Sqrt[1 - x[0]^2];

x[10]

To get many values:

{x[#], y[#]} & /@ Range[0,10]
$\endgroup$
1
  • $\begingroup$ great - thank you! :) $\endgroup$
    – martin
    Commented Oct 12, 2014 at 20:51
5
$\begingroup$

RecurrenceTable:

RecurrenceTable[{
   x[n + 1] == x[n] + (1/2) (Sqrt[1 - y[n]^2] - x[n]),
   y[n + 1] == y[n] + (1/2) (Sqrt[1 - x[n + 1]^2] - y[n]),
   x[0] == 0, y[0] == 0}, {x, y}, {n, 1, 5}] // N

{{0.5, 0.433013}, {0.700694, 0.573237}, {0.760042, 0.611556}, {0.775621, 0.621377}, {0.779567, 0.623848}}

Credit goes to Stelios for spotting a mistake in the original answer :)

$\endgroup$
0
3
$\begingroup$

Using:

f[x_, y_] := x + 0.5 (Sqrt[1 - y^2] - x)

Initial condition {0,0} first 10:

NestList[Apply[Function[{x, y}, {f[x, y], f[y, f[x, y]]}], #] &, {0, 
  0}, 10]

yields:

{{0, 0}, {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}}

Note fixed points on $y=\sqrt{1-x^2}$:

Manipulate[
 Show[ListPlot[
   NestList[
    Apply[Function[{x, y}, {f[x, y], f[y, f[x, y]]}], #] &, {a[[1]], 
     a[[2]]}, 10]], Plot[Sqrt[1 - x^2], {x, 0, 1}], 
  PlotRange -> Table[{0, 1}, {2}], Frame -> True, 
  FrameLabel -> {"x", "y"}, BaseStyle -> 16, 
  AxesOrigin -> {0, 0}], {a, {0, 0}, {1, 1}}]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ I'm very happy to know that our idea is a bit same:-) $\endgroup$
    – xyz
    Commented Oct 13, 2014 at 5:27
2
$\begingroup$

Firstly,I simplify your formular:

$$x_{n}=\frac{1}{2}\left(x_{n-1}+\sqrt{1-y_{n-1}\ ^{2}}\right)\\ y_{n}=\frac{1}{2}\left(y_{n-1}+\sqrt{1-x_{n}\ ^{2}}\right)$$

Seeing the sequences as below:

$$x_1,y_1,x_2,y_2,x_3,y_3\ldots\\ $$ I define a function:$f(x,y)=1/2(x+\sqrt{1-y^2})$ $$ x_2=f(x_1,y_1)\\ y_2=f(y_1,x_2)\\ x_3=f(x_2,y_2)\ldots $$ So considering the underlying permutation :

$$(x_1,y_1),(y_1,x_2),(x_2,y_2),(y_2,x_3) \\ \ldots$$

Solutions

$x_0=1/2,y_0=\sqrt{3}/4$

To achieve:$x_0,y_0,x_1,y_1,\dots x_{12},y_{12}$

 f[x_, y_] := 1/2 (x + Sqrt[1 - y^2]);
 xyList=
   DeleteDuplicates@
    Flatten@NestList[{#[[2]], f[Sequence @@ ##]} &, {1/2, Sqrt[3]/4}, 10] // N
 {0.5, 0.433013, 0.700694, 0.573237, 0.760042, 0.611556, 0.775621, 0.621377, 
    0.779567, 0.623848, 0.780556, 0.624467}

Lastly

 xlst=xyList[[Range[1, 12, 2]]]
{0.5, 0.700694, 0.760042, 0.775621, 0.779567, 0.780556}
 ylst=xyList[[Range[2, 12, 2]]]
{0.433013, 0.573237, 0.611556, 0.621377, 0.623848, 0.624467}
$\endgroup$

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.