[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] use of recurrence relation while computing mean, variance etc

From: Awhan Patnaik
Subject: [Help-gsl] use of recurrence relation while computing mean, variance etc.
Date: Sun, 7 Aug 2011 04:22:49 +0530

hello all,

i have 3 questions to bother you with.

1) what is the motivation behind using the recurrence relation for the
computation of the mean ? seems to me that a division by the number of
elements *after* the for loop will result in fewer division operations
than the current implementation. i have noticed the use of recurrence
type computation of variance as well.

2) many functions have a return type of double but the quantity of
interest that is to be returned is declared as a long double inside
the function body. why is this done? is it that conversion from a long
double to double results in less loss of precision?

3) declaration of variables inside the for loop body e.g. delta in the
following snippet from variance_source.c

/* find the sum of the squares */
  for (i = 0; i < n; i++)
      const long double delta = (data[i * stride] - mean);
      variance += (delta * delta - variance) / (i + 1);

does the compiler keep creating a local delta each time control enters
the loop or is it created once but treated as a local variable and
valid only in the scope of the for loop?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]