~ubuntu-branches/ubuntu/trusty/gsl-ref-html/trusty

« back to all changes in this revision

Viewing changes to Example-statistical-programs.html

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2006-04-12 19:46:32 UTC
  • mfrom: (1.3.1 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060412194632-c9lodpl075pv9si3
Tags: 1.8-1
* New upstream release 1.8
* As with previous releases, the sources were obtained from the FSF web 
  pages by means of a wget call (c.f. the debian/rules target 'upstream')

* debian/control: Standards-Version increased to 3.6.2
* debian/copyright: Updated FSF address
* debian/rules: Set DH_COMPAT=4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html lang="en">
 
2
<head>
 
3
<title>Example statistical programs - GNU Scientific Library -- Reference Manual</title>
 
4
<meta http-equiv="Content-Type" content="text/html">
 
5
<meta name="description" content="GNU Scientific Library -- Reference Manual">
 
6
<meta name="generator" content="makeinfo 4.8">
 
7
<link title="Top" rel="start" href="index.html#Top">
 
8
<link rel="up" href="Statistics.html#Statistics" title="Statistics">
 
9
<link rel="prev" href="Median-and-Percentiles.html#Median-and-Percentiles" title="Median and Percentiles">
 
10
<link rel="next" href="Statistics-References-and-Further-Reading.html#Statistics-References-and-Further-Reading" title="Statistics References and Further Reading">
 
11
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
 
12
<!--
 
13
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 The GSL Team.
 
14
 
 
15
Permission is granted to copy, distribute and/or modify this document
 
16
under the terms of the GNU Free Documentation License, Version 1.2 or
 
17
any later version published by the Free Software Foundation; with the
 
18
Invariant Sections being ``GNU General Public License'' and ``Free Software
 
19
Needs Free Documentation'', the Front-Cover text being ``A GNU Manual'',
 
20
and with the Back-Cover Text being (a) (see below).  A copy of the
 
21
license is included in the section entitled ``GNU Free Documentation
 
22
License''.
 
23
 
 
24
(a) The Back-Cover Text is: ``You have freedom to copy and modify this
 
25
GNU Manual, like GNU software.''-->
 
26
<meta http-equiv="Content-Style-Type" content="text/css">
 
27
<style type="text/css"><!--
 
28
  pre.display { font-family:inherit }
 
29
  pre.format  { font-family:inherit }
 
30
  pre.smalldisplay { font-family:inherit; font-size:smaller }
 
31
  pre.smallformat  { font-family:inherit; font-size:smaller }
 
32
  pre.smallexample { font-size:smaller }
 
33
  pre.smalllisp    { font-size:smaller }
 
34
  span.sc    { font-variant:small-caps }
 
35
  span.roman { font-family:serif; font-weight:normal; } 
 
36
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
 
37
--></style>
 
38
</head>
 
39
<body>
 
40
<div class="node">
 
41
<p>
 
42
<a name="Example-statistical-programs"></a>
 
43
Next:&nbsp;<a rel="next" accesskey="n" href="Statistics-References-and-Further-Reading.html#Statistics-References-and-Further-Reading">Statistics References and Further Reading</a>,
 
44
Previous:&nbsp;<a rel="previous" accesskey="p" href="Median-and-Percentiles.html#Median-and-Percentiles">Median and Percentiles</a>,
 
45
Up:&nbsp;<a rel="up" accesskey="u" href="Statistics.html#Statistics">Statistics</a>
 
46
<hr>
 
47
</div>
 
48
 
 
49
<h3 class="section">20.9 Examples</h3>
 
50
 
 
51
<p>Here is a basic example of how to use the statistical functions:
 
52
 
 
53
<pre class="example"><pre class="verbatim">     #include &lt;stdio.h>
 
54
     #include &lt;gsl/gsl_statistics.h>
 
55
     
 
56
     int
 
57
     main(void)
 
58
     {
 
59
       double data[5] = {17.2, 18.1, 16.5, 18.3, 12.6};
 
60
       double mean, variance, largest, smallest;
 
61
     
 
62
       mean     = gsl_stats_mean(data, 1, 5);
 
63
       variance = gsl_stats_variance(data, 1, 5);
 
64
       largest  = gsl_stats_max(data, 1, 5);
 
65
       smallest = gsl_stats_min(data, 1, 5);
 
66
     
 
67
       printf ("The dataset is %g, %g, %g, %g, %g\n",
 
68
              data[0], data[1], data[2], data[3], data[4]);
 
69
     
 
70
       printf ("The sample mean is %g\n", mean);
 
71
       printf ("The estimated variance is %g\n", variance);
 
72
       printf ("The largest value is %g\n", largest);
 
73
       printf ("The smallest value is %g\n", smallest);
 
74
       return 0;
 
75
     }
 
76
</pre></pre>
 
77
   <p>The program should produce the following output,
 
78
 
 
79
<pre class="example"><pre class="verbatim">     The dataset is 17.2, 18.1, 16.5, 18.3, 12.6
 
80
     The sample mean is 16.54
 
81
     The estimated variance is 4.2984
 
82
     The largest value is 18.3
 
83
     The smallest value is 12.6
 
84
</pre></pre>
 
85
   <p>Here is an example using sorted data,
 
86
 
 
87
<pre class="example"><pre class="verbatim">     #include &lt;stdio.h>
 
88
     #include &lt;gsl/gsl_sort.h>
 
89
     #include &lt;gsl/gsl_statistics.h>
 
90
     
 
91
     int
 
92
     main(void)
 
93
     {
 
94
       double data[5] = {17.2, 18.1, 16.5, 18.3, 12.6};
 
95
       double median, upperq, lowerq;
 
96
     
 
97
       printf ("Original dataset:  %g, %g, %g, %g, %g\n",
 
98
              data[0], data[1], data[2], data[3], data[4]);
 
99
     
 
100
       gsl_sort (data, 1, 5);
 
101
     
 
102
       printf ("Sorted dataset: %g, %g, %g, %g, %g\n",
 
103
              data[0], data[1], data[2], data[3], data[4]);
 
104
     
 
105
       median 
 
106
         = gsl_stats_median_from_sorted_data (data, 
 
107
                                              1, 5);
 
108
     
 
109
       upperq 
 
110
         = gsl_stats_quantile_from_sorted_data (data, 
 
111
                                                1, 5,
 
112
                                                0.75);
 
113
       lowerq 
 
114
         = gsl_stats_quantile_from_sorted_data (data, 
 
115
                                                1, 5,
 
116
                                                0.25);
 
117
     
 
118
       printf ("The median is %g\n", median);
 
119
       printf ("The upper quartile is %g\n", upperq);
 
120
       printf ("The lower quartile is %g\n", lowerq);
 
121
       return 0;
 
122
     }
 
123
</pre></pre>
 
124
   <p>This program should produce the following output,
 
125
 
 
126
<pre class="example"><pre class="verbatim">     Original dataset: 17.2, 18.1, 16.5, 18.3, 12.6
 
127
     Sorted dataset: 12.6, 16.5, 17.2, 18.1, 18.3
 
128
     The median is 17.2
 
129
     The upper quartile is 18.1
 
130
     The lower quartile is 16.5
 
131
</pre></pre>
 
132
   </body></html>
 
133