tadd helper functions for euclidean norm operations - granular - granular dynam… | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 100fd75afdf351a48124f5058a23aa1a4ac5999d | |
parent 47f03a2170cd92c674ac784fb1cf73b1df90f9aa | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 18 Mar 2021 07:59:24 +0100 | |
add helper functions for euclidean norm operations | |
Diffstat: | |
M arrays.c | 24 ++++++++++++++++++++++++ | |
M arrays.h | 3 +++ | |
2 files changed, 27 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/arrays.c b/arrays.c | |
t@@ -290,3 +290,27 @@ normalize(const double *in, const int n) | |
return out; | |
} | |
+ | |
+double | |
+euclidean_norm(const double *a, const int n) | |
+{ | |
+ int i; | |
+ double out = 0.0; | |
+ | |
+ for (i = 0; i < n; i++) | |
+ out += pow(a[i], 2.0); | |
+ | |
+ return sqrt(out); | |
+} | |
+ | |
+double | |
+euclidean_distance(const double *a, const double *b, const int n) | |
+{ | |
+ int i; | |
+ double out = 0.0; | |
+ | |
+ for (i = 0; i < n; i++) | |
+ out += pow(b[i] - a[i], 2.0); | |
+ | |
+ return sqrt(out); | |
+} | |
diff --git a/arrays.h b/arrays.h | |
t@@ -51,4 +51,7 @@ void copy_values(const double *in, double *out, const int n); | |
double * copy(const double *in, const int n); | |
double * normalize(const double *in, const int n); | |
+double euclidean_norm(const double *a, const int n); | |
+double euclidean_distance(const double *a, const double *b, const int n); | |
+ | |
#endif |