コンテンツにスキップ

ロジスティック写像

この sample は計算ノートの例です。model を紹介し、式を示し、読者が parameter を変更できるようにし、Rust/Wasm セルから結果を描画します。

  • 実装する code の近くに置く数式。
  • model parameter を動かす reactive Rust input。
  • crates: [doc-rust] で参照する helper crate。
  • 1つの cell から出す text と chart output。

ロジスティック写像は、単純な recurrence relation から複雑な振る舞いが現れる離散 dynamical system です。

xn+1=rxn(1−xn)x_{n+1} = r x_n (1 - x_n)

ここで xnx_n は step nn の state、r は growth rate です。r や x0 を変えると Rust/Wasm で series が再計算され、plot が更新されます。

Rust + Wasm

Explore logistic map parameters

Cell actions
Cell inputs
3.20
0.20
let steps = u32::try_from(steps).map_err(|_| "steps must be non-negative".to_owned())?;
let points = doc_rust::logistic_series(r, x0, steps).map_err(|error| error.to_string())?;
let final_point = points.last().ok_or_else(|| "series is empty".to_owned())?;

println!("x_{} = {:.6}", final_point.n, final_point.x);
let coordinates: Vec<[f64; 2]> = points.iter().map(|point| [f64::from(point.n), point.x]).collect();
emit_line_chart!(&coordinates, options = &serde_json::json!({
    "xLabel": "n", "yLabel": "x", "yMin": 0, "yMax": 1, "annotations": [{ "kind": "line", "axis": "y", "value": 0.5, "label": "臨界点" }]
}));

Waiting for the runtime to start.

r が小さいと series は安定した値に近づきます。r が大きくなると周期的な振る舞いが現れます。さらに大きい値では、出力が初期値に敏感になります。

このページ形は計算ノートに向いています。数式で model を説明し、実行可能セルで読者が parameter を変え、結果を plot として確認できます。