~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/statistics/geomean.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function gm=geomean(x,orien)
 
2
//
 
3
//This function computes the geometric mean of a vector or matrix x.
 
4
//
 
5
//For a vector  or  matrix  x,  gm=geomean(x) returns in  scalar  gm the
 
6
//geometric mean of all the entries of x.
 
7
//
 
8
//gm=geomean(x,'r')(or,  equivalently,   gm=gmean(x,1)) returns  in each
 
9
//entry of the row vector gm the geometric mean of each column of x.
 
10
//
 
11
//gm=geomean(x,'c')(or,   equivalently,  gm=gmean(x,2)) returns in  each
 
12
//entry of the column vector gm the geometric mean of each row of x.
 
13
//
 
14
//References:  Wonacott, T.H. & Wonacott, R.J.; Introductory
 
15
//Statistics, J.Wiley & Sons, 1990.
 
16
//
 
17
//author: carlos klimann
 
18
//
 
19
//date: 1999-06-10
 
20
//
 
21
  if x==[] then gm=%nan, return, end
 
22
  [lhs,rhs]=argn(0)
 
23
  if rhs==0 then error('geomean requires at least one input.'), end
 
24
  if rhs==1 then
 
25
    gm=prod(x)^(1/length(x))
 
26
  elseif rhs==2
 
27
    gm=prod(x,orien).^(1/size(x,orien))
 
28
  else 
 
29
    error('The number of input parameters must be 1 or 2')
 
30
  end
 
31
endfunction