/* nag_kernel_density_estim (g10bac) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include #include #include int main(void) { Integer i, init, increment, j, n, ns; Integer exit_status=0; double enda, endb, *s=0, high, low, *smooth=0, window, *x=0; Integer ifail, *isort=0; Boolean usefft; NagError fail; INIT_FAIL(fail); Vprintf("g10bac Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%lf ", &window); Vscanf("%lf , %lf", &low, &high); /* Generate Normal (0,1) Distribution */ n = 1000; ns = 100; if (!(x = NAG_ALLOC(n, double)) || !(s = NAG_ALLOC(ns, double)) || !(smooth = NAG_ALLOC(ns, double)) || !(isort = NAG_ALLOC(ns, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } init = 0; g05cbc(init); enda = 0.0; endb = 1.0; for (i = 0; i < n; i++) x[i] = g05ddc(enda, endb); /* Perform kernel density estimation */ usefft = FALSE; ifail = 0; g10bac(n, x, window, low, high, ns, smooth, s, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g10bac.\n%s\n", fail.message); exit_status = 1; goto END; } printf(" Points Density Points Density Points Density Points Density\n"); printf(" Value Value Value Value\n\n"); increment = 25; for (i=1; i<= ns/4; i++) { printf("%10.4f %10.4f", s[i-1], smooth[i-1]); for (j=1; j <= 3; j++) { printf("%10.4f %10.4f", s[i-1+j*increment], smooth[i-1+j*increment]); } printf("\n"); } END: if (x) NAG_FREE(x); if (s) NAG_FREE(s); if (smooth) NAG_FREE(smooth); if (isort) NAG_FREE(isort); return exit_status; }