GRASS GIS 7 Programmer's Manual
7.8.4(2020)-exported
dmaxe.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <math.h>
4
#include "local_proto.h"
5
6
7
double
*
Cdhc_dmax_exp
(
double
*
x
,
int
n)
8
{
9
static
double
y[2];
10
double
mean = 0.0, zmax, tmax, *xcopy,
t
, z, fx;
11
int
i;
12
13
if
((xcopy = (
double
*)malloc(n *
sizeof
(
double
))) ==
NULL
) {
14
fprintf(stderr,
"Memory error in Cdhc_dmax_exp\n"
);
15
exit(EXIT_FAILURE);
16
}
17
18
for
(i = 0; i < n; ++i) {
19
xcopy[i] =
x
[i];
20
mean +=
x
[i];
21
}
22
mean /= n;
23
24
qsort(xcopy, n,
sizeof
(
double
),
Cdhc_dcmp
);
25
26
for
(i = 0; i < n; ++i) {
27
fx = 1 - exp(-xcopy[i] / mean);
28
z = (double)(i + 1) / (double)n - fx;
29
t
= fx - (double)i / (
double
)n;
30
if
(i == 0 || z > zmax)
31
zmax = z;
32
33
if
(i == 0 ||
t
> tmax)
34
tmax =
t
;
35
}
36
37
y[0] = zmax;
38
y[1] = tmax;
39
40
free(xcopy);
41
42
return
y;
43
}
Cdhc_dmax_exp
double * Cdhc_dmax_exp(double *x, int n)
Definition:
dmaxe.c:7
x
#define x
Cdhc_dcmp
int Cdhc_dcmp(const void *i, const void *j)
Definition:
dcmp.c:1
t
double t
Definition:
driver/set_window.c:5
NULL
#define NULL
Definition:
ccmath.h:32
cdhc
dmaxe.c
Generated on Mon Oct 5 2020 08:56:03 for GRASS GIS 7 Programmer's Manual by
1.8.20