Function russell_lab::generate3d[][src]

pub fn generate3d<F>(
    xmin: f64,
    xmax: f64,
    ymin: f64,
    ymax: f64,
    nx: usize,
    ny: usize,
    calc_z: F
) -> (Matrix, Matrix, Matrix) where
    F: Fn(f64, f64) -> f64
Expand description

Generates 3d points

Input

  • xmin, xmax – range along x
  • ymin, ymax – range along y
  • nx – is the number of points along x (must be >= 2)
  • ny – is the number of points along y (must be >= 2)
  • calc_z – is a function of (xij, yij) that calculates zij

Output

  • x, y, z – (ny by nx) matrices

Example

use russell_lab::generate3d;
let (nx, ny) = (5, 3);
let (x, y, z) = generate3d(-1.0, 1.0, -2.0, 2.0, nx, ny, |x, y| x * x + y * y);
assert_eq!(
    format!("{}", x),
    "┌                          ┐\n\
     │   -1 -0.5    0  0.5    1 │\n\
     │   -1 -0.5    0  0.5    1 │\n\
     │   -1 -0.5    0  0.5    1 │\n\
     └                          ┘"
);
assert_eq!(
    format!("{}", y),
    "┌                ┐\n\
     │ -2 -2 -2 -2 -2 │\n\
     │  0  0  0  0  0 │\n\
     │  2  2  2  2  2 │\n\
     └                ┘"
);
assert_eq!(
    format!("{}", z),
    "┌                          ┐\n\
     │    5 4.25    4 4.25    5 │\n\
     │    1 0.25    0 0.25    1 │\n\
     │    5 4.25    4 4.25    5 │\n\
     └                          ┘"
);