Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - English


harmean

harmonic mean : inverse of the inverses average (without zeros)

Syntax

hm = harmean(x)
hm = harmean(x, orientation)

Arguments

x

vector, matrix, or hypermatrix of real or complex numbers or polynomials. Rationals not supported.

orientation

index of the dimension along which the harmean is computed. It can be either

  • a character "*" (default), "r", "c" or "m". "m" is equivalent to find(size(x)>1,1).
  • a positive integer. 1 is equivalent to "r" and 2 is equivalent to "c".

hm

scalar, or row (if "r" is used), or column (if "c" is used). If x are polynomials, hm is of rational type.

Description

This function computes the harmonic mean of input values = inverse of the average of inversed non-zero values.

hm = harmean(x) or hm = harmean(x, '*') returns in scalar hm the harmonic mean of all the entries.

hm = harmean(x,'r') (or, equivalently, hm = harmean(x, 1) ) returns in each entry of the row vector hm the harmonic mean of each column of x.

hm = harmean(x,'c') (or, equivalently, hm = harmean(x, 2) ) returns in each entry of the column vector hm the harmonic mean of each row of x.

If x is an hypermatrix and a "r", 1, "c", 2 flag is used, an error occurs.

Examples

harmean(1:10) // Returns 1 / mean(1 ./(1:10))
h = harmean([1 1 0 1 0 1])  // returns 1: zeros are not considered
1 / mean(1./[1 1 0 1 0 1])  // returns 0, as soon as a zero is present

x = grand(3, 4, "uin",-10, 10)
harmean(x)
harmean(x, "r")
harmean(x, 2)

// Hypermatrix
x = grand(3,4,2, "uin",-10, 10)
harmean(x)
// warning: harmean(x, "r") and harmean(x, 3) generate one error: not supported !

harmean([%z 0])
harmean([%z %z/2])
harmean([%z %i+%z])
harmean([%z %i+%z]) == 1 / ((1/%z + 1/(%i+%z))/2)

Bibliography

Wonacott, T.H. & Wonacott, R.J.; Introductory Statistics, fifth edition, J.Wiley & Sons, 1990.

See also

  • mean — mean of all values, or means along a given dimension
  • geomean — geometric mean
Report an issue
<< geomean Mean Central Tendency mean >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:49:16 CEST 2024