GRASS Programmer's Manual  6.5.svn(2014)-r66266
N_tools.c
Go to the documentation of this file.
1
2 /*****************************************************************************
3 *
4 * MODULE: Grass PDE Numerical Library
5 * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
6 * soerengebbert <at> gmx <dot> de
7 *
8 * PURPOSE: Array managment functions
9 * part of the gpde library
10 *
11 * COPYRIGHT: (C) 2000 by the GRASS Development Team
12 *
13 * This program is free software under the GNU General Public
14 * License (>=v2). Read the file COPYING that comes with GRASS
15 * for details.
16 *
17 *****************************************************************************/
18
19 #include "grass/N_pde.h"
20 #include "grass/glocale.h"
21 #include <math.h>
22
23
33 double N_calc_arith_mean(double a, double b)
34 {
35  double val = 0;
36
37  val = (a + b) / 2.0;
38
39  return val;
40 }
41
53 double N_calc_arith_mean_n(double *a, int size)
54 {
55  double val = 0.0;
56
57  int i;
58
59  for (i = 0; i < size; i++)
60  val += a[i];
61
62  val = (val / (double)size);
63
64  return val;
65 }
66
67
77 double N_calc_geom_mean(double a, double b)
78 {
79  double val = 0;
80
81  val = sqrt(a * b);
82
83  return val;
84 }
85
97 double N_calc_geom_mean_n(double *a, int size)
98 {
99  double val = 1;
100
101  int i;
102
103  for (i = 0; i < size; i++)
104  val *= a[i];
105
106  val = (double)pow((long double)val, (long double)1.0 / (long double)size);
107
108  return val;
109 }
110
111
121 double N_calc_harmonic_mean(double a, double b)
122 {
123  double val = 0.0;
124
125  if ((a + b) != 0)
126  val = 2.0 * (a * b) / (a + b);
127
128  return val;
129 }
130
142 double N_calc_harmonic_mean_n(double *a, int size)
143 {
144  double val = 0;
145
146  int i;
147
148  for (i = 0; i < size; i++)
149  if (a[i] != 0.0)
150  val += 1.0 / a[i];
151  else
152  return 0.0;
153
154  if (val == 0.0)
155  return 0.0;
156  else
157  val = 1.0 / (1.0 / (double)size * val);
158
159  return val;
160 }
161
162
172 double N_calc_quad_mean(double a, double b)
173 {
174  double val = 0.0;
175
176  val = sqrt((a * a + b * b) / 2.0);
177
178  return val;
179 }
180
192 double N_calc_quad_mean_n(double *a, int size)
193 {
194  double val = 0;
195
196  int i;
197
198  for (i = 0; i < size; i++)
199  val += a[i] * a[i];
200
201  val = sqrt(val / (double)size);
202
203  return val;
204 }
float b
Definition: named_colr.c:8
double N_calc_harmonic_mean_n(double *a, int size)
Calculate the harmonical mean of the values in vector a of size n.
Definition: N_tools.c:142
double N_calc_geom_mean(double a, double b)
Calculate the geometrical mean of values a and b.
Definition: N_tools.c:77
double N_calc_geom_mean_n(double *a, int size)
Calculate the geometrical mean of the values in vector a of size n.
Definition: N_tools.c:97
Calculate the quadratic mean of values a and b.
Definition: N_tools.c:172
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334