Crates.io | linear_curve_fit |
lib.rs | linear_curve_fit |
version | 0.2.0 |
source | src |
created_at | 2024-11-02 13:04:59.456546 |
updated_at | 2024-11-07 02:53:24.939503 |
description | A no_std and no heap memory library for linear curve coefficents calculation. |
homepage | https://github.com/Joker2770/linear_curve_fit |
repository | https://github.com/Joker2770/linear_curve_fit |
max_upload_size | |
id | 1432860 |
size | 45,779 |
A no_std
and no heap memory library for linear curve coefficents calculation.
use linear_curve_fit::linear_curve::LinearCoefficents2D;
let mut linear_coefficents = LinearCoefficents2D::default();
let x_test_arr = [
-2.8f32, -1.6f32, -0.5f32, 5.0f32, 5.4f32, 6.7f32, 10.3f32, 13.8f32,
];
let y_test_arr = [
33.1f32, 21.1f32, 9.9f32, -45.2f32, -49.1f32, -61.9f32, -98.1f32, -132.99f32,
];
let (xm_data, ym_data) =
LinearCoefficents2D::get_matrix_data_from_8_points(&x_test_arr, &y_test_arr);
linear_coefficents.get_coefficients_from_8_matrix_data(&xm_data, &ym_data, 0.0001f32);
let (k, b) = linear_coefficents.coefficents();
assert!(k < -9.5f32 && k > -10.5f32);
assert!(b > 4.5f32 && b < 5.5f32);
assert!((linear_coefficents.value(5.0) + 45.2f32).abs() < 1.0f32);
assert!((linear_coefficents.value(10.3) + 98.1f32).abs() < 1.0f32);