Last active
February 3, 2026 20:26
-
-
Save dacr/995f84a40a245354919901f201570edc to your computer and use it in GitHub Desktop.
the logistic map / La suite logistique / published by https://github.com/dacr/code-examples-manager #d39c9323-49f4-46ec-a7a2-f81d5fdf0893/b8782b6b9f60dccf746dfb86f0d27c2d30712421
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : the logistic map / La suite logistique | |
| // keywords : math, logistic-map, fractal, chaos, breeze | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : d39c9323-49f4-46ec-a7a2-f81d5fdf0893 | |
| // created-on : 2021-02-26T15:34:32Z | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' | |
| // logistic map info -> https://en.wikipedia.org/wiki/Logistic_map | |
| // veritasium video -> https://www.youtube.com/watch?v=ovJcsL7vyrk | |
| import $ivy.`org.plotly-scala::plotly-render:0.8.1` | |
| import plotly._ ,element._ ,layout._ ,Plotly._ | |
| // ================================================================================================= | |
| def logMap(xn: Double, r: Double): Double = r * xn * (1 - xn) | |
| // ================================================================================================= | |
| val points = { | |
| LazyList | |
| .iterate(0d)(_ + 0.001d) | |
| .takeWhile(_ <= 1.0d) | |
| .map(x => x->logMap(x, 1.5)) | |
| } | |
| val (xs, ys) = points.unzip | |
| println("Number of points generated : "+points.size) | |
| // ================================================================================================= | |
| val plotlyData = Seq( | |
| Scatter(xs, ys) | |
| .withName("LogisticFunction") | |
| .withMode(ScatterMode(ScatterMode.Markers)) | |
| .withMarker(Marker().withSize(1)) | |
| ) | |
| val plotlyLayout = Layout().withTitle("LogisticFunction").withHeight(800).withWidth(1200) | |
| plot("plot.html", plotlyData, plotlyLayout) | |
| //scala.io.StdIn.readLine("Press enter to quit") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment