﻿ HarmonicMean – Algosim documentation
Algosim documentation: HarmonicMean

# HarmonicMean

Computes the harmonic mean of all elements in a container or in a sequence. The elements must be numbers.

## Syntax

• `HarmonicMean(X)`

• `X` is a vector, matrix, list, or set

• `HarmonicMean(expr, var, a, b)`

• `expr` is an expression in one variable `var`

• `var` is the variable in `expr`

• `a` is the lower bound

• `b` is the upper bound

## Description

### Computing the mean of a container

If `X` is a non-empty container of numbers, then `HarmonicMean(X)` is the harmonic mean of all elements in `X`.

The following container types are supported:

• vectors

• the result is the mean of all components

• matrices

• the result is the mean of all entries

• lists containing numbers

• the result is the mean of all numbers

• sets containing numbers

• the result is the mean of all numbers

Typewise, the elements may be either real or complex, and the result is complex iff at least one of the elements is complex.

### Computing the mean of a sequence

`HarmonicMean(expr, var, a, b)` computes the harmonic mean of the expression `expr` in one variable `var` as `var` takes all integer values from `a` to `b` (inclusively).

`expr` must return a number.

## Examples

### Computing the mean of a container

`HarmonicMean(❨5, 1, 2, 6, 3, 8, 4, 10, 2, 3❩)`
`2.85035629454	(=1200/421)`

### Computing the mean of a sequence

`HarmonicMean(n^2 + 3⋅n + 1, n, 1, 100)`
`186.411917683`