File: example_FuncStr.c

package info (click to toggle)
unuran 1.11.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,344 kB
  • sloc: ansic: 204,607; sh: 4,783; perl: 3,160; makefile: 839; cpp: 24
file content (39 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* ------------------------------------------------------------- */
/* File: example_FuncStr.c                                       */
/* ------------------------------------------------------------- */

/* Include UNURAN header file.                                   */
#include <unuran.h>

/* ------------------------------------------------------------- */

/* Example how to define the PDF for a continuous univariate     */
/* distribution using a function string.                         */

/* ------------------------------------------------------------- */

int main(void)
{
  UNUR_DISTR *distr;    /* distribution object */
  char *pdfstr;

  /* Get empty distribution object for a continuous distribution */
  distr = unur_distr_cont_new();

  /* Set PDF using function string */
  unur_distr_cont_set_pdfstr(distr,"1-x*x");
  unur_distr_cont_set_domain(distr,-1.,1.);
 
  /* Read function string from distribution object */
  pdfstr = unur_distr_cont_get_pdfstr(distr);
  printf("functionstring: %s\n",pdfstr);

  /* Destroy distribution object and clear memory */
  unur_distr_free(distr);
  free (pdfstr);

  exit (EXIT_SUCCESS);

} /* end of main() */

/* ------------------------------------------------------------- */