create account

The logistic map in R by snippets

View this thread on: hive.blogpeakd.comecency.com
· @snippets ·
$1.38
The logistic map in R
I am just trying to learn the logistic map, so here are some notes and the R code snippets.

Basically what the logistic map does, is a equation that returns the next value based on current value. 

The formula is Xn+1 = R * Xn * (1-Xn).

- Xn is the value of X in the nth iteration.
- Xn+1 is the next value of Xn, which we calculate.
- R is the parameter.

This equation has been used in several real life problems to model the situation. One example is [population growth](https://plus.maths.org/content/maths-minute-logistic-map).


In its crude form, it looks like this when coding in R.

```
R=3

x0=0.5
x1=R*x0*(1-x0)
x2=R*x1*(1-x1)
x3=R*x2*(1-x2)
x4=R*x2*(1-x3)
x5=R*x2*(1-x4)
x6=R*x2*(1-x5)

```

We can try to plot it and iterate over many rounds through a loop.

```
R=3
a=0.5

points<-c(a)


for (i in 1:30){
  b<-R*a*(1-a)
  a=b
  points[i]<-a
}

plot(points)
 
```


![Screenshot 2024-05-30 at 5.22.03 AM.png](https://files.peakd.com/file/peakd-hive/snippets/23tHbKgySUppzvx8UUFyCGXkn6ej9cBMJWVf2edgyuyvFgaBZge9DJZmaGk2AhLAHsN6Y.png)

We see a stabilisation with R being 3. This is also call a fixed point when there is a stabilisation to a value.

Let's try with R being 3.4.

```
R=3.4
a=0.5

points<-c(a)


for (i in 1:30){
  b<-R*a*(1-a)
  a=b
  points[i]<-a
}

plot(points)
```

Now we see a bistable state, i.e. X value fluctuating up and down.

![Screenshot 2024-05-30 at 5.28.57 AM.png](https://files.peakd.com/file/peakd-hive/snippets/23t8CfKPvq6siMpQSRxVxWaYWmRND59F7WSTD7RDZV9WBox9f6zYN8KT82V9vcPX2ZVeK.png)

Apparently, at R of approximately 3.5699456, not far from 3.4, something strange starts to happen.

  

```

R=3.5699456 
a=0.5

points<-c(a)


for (i in 1:30){
  b<-R*a*(1-a)
  a=b
  points[i]<-a
}

plot(points)

```

The bistable states starts to be changed.

![Screenshot 2024-05-30 at 5.32.57 AM.png](https://files.peakd.com/file/peakd-hive/snippets/23t8CfKPvrR3VDy1crkoFEbTbrKwKQjLN98ddVYUJVRxDYhAVH4GpJMwwzPT3eggrXxQK.png)

And when R is 3.65, some kind of messy plot emerges.

![Screenshot 2024-05-30 at 5.36.43 AM.png](https://files.peakd.com/file/peakd-hive/snippets/23sxozwpQz1dWV2oBNvU29zDESeC8Bgcx4PDwKCSWKPrLeTxA9uzz8ttCXeKo6FFup5wH.png)
 
At R at 3.999999999999...

![Screenshot 2024-05-30 at 5.39.13 AM.png](https://files.peakd.com/file/peakd-hive/snippets/23tSyz4YxQSgdZeqZd7ZewMuSqoBtxswrVEk2XxKxyoXmNXoWC1pouCsj4GALsuJrnWsH.png)
  
Finally, at R = 4.0. We get back another fixed point.

![Screenshot 2024-05-30 at 5.41.30 AM.png](https://files.peakd.com/file/peakd-hive/snippets/23tSyz4YxQSghaZUQkwzGvF8j2BybJxzUNhsMgAfP6dBkioTnGyUhMorraZB3NZhFJP5r.png)

 
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 110 others
properties (23)
authorsnippets
permlinkthe-logistic-map-in-r
categoryhive-196387
json_metadata{"app":"peakd/2024.5.5","format":"markdown","tags":["programming","proofofbrain","education","stemsocial","leofinance","rstats"],"users":[],"image":["https://files.peakd.com/file/peakd-hive/snippets/23tHbKgySUppzvx8UUFyCGXkn6ej9cBMJWVf2edgyuyvFgaBZge9DJZmaGk2AhLAHsN6Y.png","https://files.peakd.com/file/peakd-hive/snippets/23t8CfKPvq6siMpQSRxVxWaYWmRND59F7WSTD7RDZV9WBox9f6zYN8KT82V9vcPX2ZVeK.png","https://files.peakd.com/file/peakd-hive/snippets/23t8CfKPvrR3VDy1crkoFEbTbrKwKQjLN98ddVYUJVRxDYhAVH4GpJMwwzPT3eggrXxQK.png","https://files.peakd.com/file/peakd-hive/snippets/23sxozwpQz1dWV2oBNvU29zDESeC8Bgcx4PDwKCSWKPrLeTxA9uzz8ttCXeKo6FFup5wH.png","https://files.peakd.com/file/peakd-hive/snippets/23tSyz4YxQSgdZeqZd7ZewMuSqoBtxswrVEk2XxKxyoXmNXoWC1pouCsj4GALsuJrnWsH.png","https://files.peakd.com/file/peakd-hive/snippets/23tSyz4YxQSghaZUQkwzGvF8j2BybJxzUNhsMgAfP6dBkioTnGyUhMorraZB3NZhFJP5r.png"]}
created2024-05-29 21:44:09
last_update2024-05-29 21:44:09
depth0
children2
last_payout2024-06-05 21:44:09
cashout_time1969-12-31 23:59:59
total_payout_value0.702 HBD
curator_payout_value0.675 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,608
author_reputation801,725,525,485
root_title"The logistic map in R"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,043,773
net_rshares3,398,708,228,905
author_curate_reward""
vote details (174)
@hivebuzz ·
Congratulations @snippets! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

<table><tr><td><img src="https://images.hive.blog/60x70/https://hivebuzz.me/@snippets/posts.png?202405300018"></td><td>You published more than 20 posts.<br>Your next target is to reach 30 posts.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@snippets) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Check out our last posts:**
<table><tr><td><a href="/hive-122221/@hivebuzz/pud-202406"><img src="https://images.hive.blog/64x128/https://i.imgur.com/805FIIt.jpg"></a></td><td><a href="/hive-122221/@hivebuzz/pud-202406">Hive Power Up Day - June 1st 2024</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-1717028973
categoryhive-196387
json_metadata{"image":["https://hivebuzz.me/notify.t6.png"]}
created2024-05-30 00:29:33
last_update2024-05-30 00:29:33
depth1
children0
last_payout2024-06-06 00:29:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length897
author_reputation369,428,689,994,553
root_title"The logistic map in R"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,046,021
net_rshares0
@stemsocial ·
re-snippets-the-logistic-map-in-r-20240530t215104745z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-snippets-the-logistic-map-in-r-20240530t215104745z
categoryhive-196387
json_metadata{"app":"STEMsocial"}
created2024-05-30 21:51:03
last_update2024-05-30 21:51:03
depth1
children0
last_payout2024-06-06 21:51:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,920,436,264,631
root_title"The logistic map in R"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,073,981
net_rshares0