From a58892044dab43179f3c11b3161666b25e09cd3a Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 13 Apr 2020 00:23:55 +0200 Subject: [PATCH] bugfix h2linspace --- sbp/src/utils.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sbp/src/utils.rs b/sbp/src/utils.rs index 961f7d8..6782734 100644 --- a/sbp/src/utils.rs +++ b/sbp/src/utils.rs @@ -294,18 +294,19 @@ pub fn json_to_vortex(mut json: JsonValue) -> super::euler::VortexParameters { } pub fn h2linspace(start: Float, end: Float, n: usize) -> ndarray::Array1 { - let h = 1.0 / (n - 2) as Float; + let h = (end - start) / (n - 2) as Float; ndarray::Array1::from_shape_fn(n, |i| match i { 0 => start, i if i == n - 1 => end, - i => h * (i as Float - 0.5), + i => start + h * (i as Float - 0.5), }) } #[test] fn test_h2linspace() { - let x = h2linspace(0.0, 1.0, 50); - approx::assert_abs_diff_eq!(x[0], 0.0, epsilon = 1e-6); + let x = h2linspace(-1.0, 1.0, 50); + println!("{}", x); + approx::assert_abs_diff_eq!(x[0], -1.0, epsilon = 1e-6); approx::assert_abs_diff_eq!(x[49], 1.0, epsilon = 1e-6); let hend = x[1] - x[0]; let h = x[2] - x[1];