1
$\begingroup$

How to can I get RecurrenceTable to deal with a piecewise function?

For example,

$ \qquad x_{n+1}= x_n(1.5-0.5x_n)\qquad \text{if $x_n\ge0.5$}\\ \qquad x_{n+1}= x_n(0.5+0.5x_n)\qquad \text{if $x_n<0,5$}\\ \qquad x_0=0.2 $

$\endgroup$
  • $\begingroup$ Welcome to Mathematica SE. I have the impression that there's something wrong in your equations, please check them. As they are, they do not define a recursion. $\endgroup$ – Roman Apr 29 at 16:57
  • $\begingroup$ I asked that meaning: we may write that x[n+1]=x[n](1,5-0,5x[n]) if x[n]>=0,5; x[n+1]=x[n](0,5+0,5x[n]) if x[n]<0,5, x[0]==0.2 $\endgroup$ – Javohir Usmonov Apr 29 at 17:01
  • $\begingroup$ Just edit your question to reflect what you just wrote. $\endgroup$ – Roman Apr 29 at 17:06
  • $\begingroup$ All values $x(n)$ are less that 0.5 in your example, so the case distinction is not necessary. $\endgroup$ – Roman Apr 29 at 17:15
1
$\begingroup$

This answer is similar to @Roman's, but uses a simpler version of Piecewise and is set for easy variation of both x[1] and max.

With[{x1 = .75, nmax = 8},
  RecurrenceTable[
    {x[n + 1] == Piecewise[{{x[n] (1 - x[n])/2, x[n] < 1/2}}, x[n] (3 - x[n])/2], 
     x[1] == x1},
    x, {n, nmax}]]

{0.75, 0.84375, 0.909668, 0.950754, 0.974164, 0.986748, 0.993286, 0.996621}

$\endgroup$
  • $\begingroup$ Thank you a lot $\endgroup$ – Javohir Usmonov Apr 30 at 7:36
2
$\begingroup$
RecurrenceTable[{x[0] == 0.2,
  x[n + 1] == Piecewise[{{x[n] (3/2 - 1/2 x[n]), x[n] >= 1/2},
                         {x[n] (1/2 + 1/2 x[n]), x[n] < 1/2}}]},
  x[n], {n, 0, 10}]

{0.2, 0.12, 0.0672, 0.0358579, 0.0185719, 0.00945838, 0.00477392, 0.00239836, 0.00120205, 0.00060175, 0.000301056}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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