File: geomean.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (31 lines) | stat: -rw-r--r-- 974 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
function gm=geomean(x,orien)
//
//This function computes the geometric mean of a vector or matrix x.
//
//For a vector  or  matrix  x,  gm=geomean(x) returns in  scalar  gm the
//geometric mean of all the entries of x.
//
//gm=geomean(x,'r')(or,  equivalently,   gm=gmean(x,1)) returns  in each
//entry of the row vector gm the geometric mean of each column of x.
//
//gm=geomean(x,'c')(or,   equivalently,  gm=gmean(x,2)) returns in  each
//entry of the column vector gm the geometric mean of each row of x.
//
//References:  Wonacott, T.H. & Wonacott, R.J.; Introductory
//Statistics, J.Wiley & Sons, 1990.
//
//author: carlos klimann
//
//date: 1999-06-10
//
  if x==[] then gm=%nan, return, end
  [lhs,rhs]=argn(0)
  if rhs==0 then error('geomean requires at least one input.'), end
  if rhs==1 then
    gm=prod(x)^(1/length(x))
  elseif rhs==2
    gm=prod(x,orien).^(1/size(x,orien))
  else 
    error('The number of input parameters must be 1 or 2')
  end
endfunction