From 643204e807d5e78f883fc30dc7383a209e86dbc5 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Wed, 17 Oct 2018 09:33:29 -0500 Subject: fix a bug in the theta0 calculation for a path This commit fixes a bug in the calculation of the average rms width of the angular distribution for a path with a KL expansion. I also made a lot of updates to the test-path program: - plot the distribution of the KL expansion coefficients - plot the standard deviation of the angular distribution as a function of distance along with the prediction - plot the simulated and reconstructed path in 3D --- src/misc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/misc.c') diff --git a/src/misc.c b/src/misc.c index 189d49b..6f50033 100644 --- a/src/misc.c +++ b/src/misc.c @@ -397,3 +397,30 @@ double norm_cdf(double x, double mu, double sigma) * standard deviation `sigma`. */ return erfc(-(x-mu)/(sqrt(2)*sigma))/2.0; } + +double mean(const double *x, size_t n) +{ + /* Returns the mean of the array `x`. */ + size_t i; + double sum = 0.0; + + for (i = 0; i < n; i++) + sum += x[i]; + + return sum/n; +} + +double std(const double *x, size_t n) +{ + /* Returns the standard deviation of the array `x`. */ + size_t i; + double sum, mu; + + mu = mean(x,n); + + sum = 0.0; + for (i = 0; i < n; i++) + sum += pow(x[i]-mu,2); + + return sqrt(sum/n); +} -- cgit