Last active
April 2, 2023 10:13
-
-
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/b1cbc7bc2fa30e9641aaa280f4a6b57d9518a3f1
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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// 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