diff --git a/russell_lab/data/figures/math_elliptic_functions_e.svg b/russell_lab/data/figures/math_elliptic_functions_e.svg new file mode 100644 index 00000000..c2eb0abd --- /dev/null +++ b/russell_lab/data/figures/math_elliptic_functions_e.svg @@ -0,0 +1,802 @@ + + + + + + + + 2024-04-27T15:53:50.355659 + image/svg+xml + + + Matplotlib v3.6.3, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/russell_lab/data/figures/math_elliptic_functions_f.svg b/russell_lab/data/figures/math_elliptic_functions_f.svg new file mode 100644 index 00000000..8d304f7b --- /dev/null +++ b/russell_lab/data/figures/math_elliptic_functions_f.svg @@ -0,0 +1,847 @@ + + + + + + + + 2024-04-27T15:53:49.910013 + image/svg+xml + + + Matplotlib v3.6.3, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/russell_lab/data/figures/math_elliptic_functions_pi.svg b/russell_lab/data/figures/math_elliptic_functions_pi.svg new file mode 100644 index 00000000..7ea1a7c0 --- /dev/null +++ b/russell_lab/data/figures/math_elliptic_functions_pi.svg @@ -0,0 +1,710 @@ + + + + + + + + 2024-04-27T15:53:50.803770 + image/svg+xml + + + Matplotlib v3.6.3, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/russell_lab/examples/math_elliptic_functions.rs b/russell_lab/examples/math_elliptic_functions.rs new file mode 100644 index 00000000..62de7323 --- /dev/null +++ b/russell_lab/examples/math_elliptic_functions.rs @@ -0,0 +1,54 @@ +use plotpy::{Curve, Plot}; +use russell_lab::math::{GOLDEN_RATIO, PI}; +use russell_lab::*; + +const OUT_DIR: &str = "/tmp/russell_lab/"; + +fn main() -> Result<(), StrError> { + // F + let xx = Vector::linspace(0.0, PI / 2.0, 101)?; + let yy = xx.get_mapped(|x| math::elliptic_f(x, 0.5).unwrap()); + let mut curve = Curve::new(); + curve + .set_line_color("#E9708E") + .set_line_width(2.5) + .draw(xx.as_data(), yy.as_data()); + let path = format!("{}/math_elliptic_functions_f.svg", OUT_DIR); + let mut plot = Plot::new(); + plot.add(&curve) + .grid_labels_legend("$\\phi$", "$F(\\phi,1/2)$") + .set_figure_size_points(GOLDEN_RATIO * 280.0, 280.0) + .save(&path)?; + + // E + let xx = Vector::linspace(0.0, PI / 2.0, 101)?; + let yy = xx.get_mapped(|x| math::elliptic_e(x, 0.5).unwrap()); + let mut curve = Curve::new(); + curve + .set_line_color("#4C689C") + .set_line_width(2.5) + .draw(xx.as_data(), yy.as_data()); + let path = format!("{}/math_elliptic_functions_e.svg", OUT_DIR); + let mut plot = Plot::new(); + plot.add(&curve) + .grid_labels_legend("$\\phi$", "$E(\\phi,1/2)$") + .set_figure_size_points(GOLDEN_RATIO * 280.0, 280.0) + .save(&path)?; + + // Π + let xx = Vector::linspace(0.0, 0.9 * PI / 2.0, 101)?; + let yy = xx.get_mapped(|x| math::elliptic_pi(1.0, x, 0.5).unwrap()); + let mut curve = Curve::new(); + curve + .set_line_color("#58B090") + .set_line_width(2.5) + .draw(xx.as_data(), yy.as_data()); + let path = format!("{}/math_elliptic_functions_pi.svg", OUT_DIR); + let mut plot = Plot::new(); + plot.add(&curve) + .grid_labels_legend("$\\phi$", "$\\Pi(1,\\phi,1/2)$") + .set_figure_size_points(GOLDEN_RATIO * 280.0, 280.0) + .save(&path)?; + + Ok(()) +} diff --git a/russell_lab/src/math/elliptic.rs b/russell_lab/src/math/elliptic.rs index aad0b35f..e38b8da6 100644 --- a/russell_lab/src/math/elliptic.rs +++ b/russell_lab/src/math/elliptic.rs @@ -37,6 +37,20 @@ use crate::StrError; /// /// * Press WH, Teukolsky SA, Vetterling WT, Flannery BP (2007) Numerical Recipes: The Art of /// Scientific Computing. Third Edition. Cambridge University Press. 1235p. +/// +/// # Examples +/// +/// ![Elliptic F](https://raw.githubusercontent.com/cpmech/russell/main/russell_lab/data/figures/math_elliptic_functions_f.svg) +/// +/// ``` +/// use russell_lab::*; +/// +/// fn main() -> Result<(), StrError> { +/// approx_eq(math::elliptic_f(math::PI / 4.0, 0.5)?, 0.82601787624924519, 1e-15); +/// // Mathematica: N[EllipticF[Pi/4, 1/2], 17] +/// Ok(()) +/// } +/// ``` pub fn elliptic_f(phi: f64, m: f64) -> Result { if phi < 0.0 || m < 0.0 { return Err("phi and m must be non-negative"); @@ -97,6 +111,20 @@ pub fn elliptic_f(phi: f64, m: f64) -> Result { /// /// * Press WH, Teukolsky SA, Vetterling WT, Flannery BP (2007) Numerical Recipes: The Art of /// Scientific Computing. Third Edition. Cambridge University Press. 1235p. +/// +/// # Examples +/// +/// ![Elliptic E](https://raw.githubusercontent.com/cpmech/russell/main/russell_lab/data/figures/math_elliptic_functions_e.svg) +/// +/// ``` +/// use russell_lab::*; +/// +/// fn main() -> Result<(), StrError> { +/// approx_eq(math::elliptic_e(math::PI / 4.0, 0.5)?, 0.74818650417766138, 1e-15); +/// // Mathematica: N[EllipticE[Pi/4, 1/2], 17] +/// Ok(()) +/// } +/// ``` pub fn elliptic_e(phi: f64, m: f64) -> Result { if phi < 0.0 || m < 0.0 { return Err("phi and m must be non-negative"); @@ -162,6 +190,20 @@ pub fn elliptic_e(phi: f64, m: f64) -> Result { /// Scientific Computing. Third Edition. Cambridge University Press. 1235p. /// * Abramowitz M, Stegun IA (1972) Handbook of Mathematical Functions with Formulas, Graphs, /// and Mathematical Tables. U.S. Department of Commerce, NIST +/// +/// # Examples +/// +/// ![Elliptic Pi](https://raw.githubusercontent.com/cpmech/russell/main/russell_lab/data/figures/math_elliptic_functions_pi.svg) +/// +/// ``` +/// use russell_lab::*; +/// +/// fn main() -> Result<(), StrError> { +/// approx_eq(math::elliptic_pi(1.0, math::PI / 4.0, 0.5)?, 1.0616956754627997, 1e-15); +/// // Mathematica: N[EllipticPi[1, Pi/4, 1/2], 17] +/// Ok(()) +/// } +/// ``` pub fn elliptic_pi(n: f64, phi: f64, m: f64) -> Result { if phi < 0.0 || m < 0.0 { return Err("phi and m must be non-negative");