tadd dot product function - granular - granular dynamics simulation | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit f4eaf592d0d80b9eed6e31d89337a6b4eebcef40 | |
parent 8617d6d7191d79d1fef9852751a40b5d40e9b936 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Wed, 21 Apr 2021 13:52:45 +0200 | |
add dot product function | |
Diffstat: | |
M arrays.c | 12 ++++++++++++ | |
M arrays.h | 1 + | |
2 files changed, 13 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/arrays.c b/arrays.c | |
t@@ -327,3 +327,15 @@ euclidean_distance(const double *a, const double *b, cons… | |
return sqrt(out); | |
} | |
+ | |
+double | |
+dot(const double *a, const double *b, const int n) | |
+{ | |
+ int i; | |
+ double out = 0.0; | |
+ | |
+ for (i = 0; i < n; i++) | |
+ out += a[i] * b[i]; | |
+ | |
+ return out; | |
+} | |
diff --git a/arrays.h b/arrays.h | |
t@@ -53,5 +53,6 @@ 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); | |
+double dot(const double *a, const double *b, const int n); | |
#endif |