The **geometric mean** is another type of average which shows the central tendency of a set of data. To calculate the geometric mean of a set of *N* data values we need to extract the *Nth* root of their product.

In mathematics there is no particular notation for the geometric mean. For our example we are going to use:

\[x_{GM} = \sqrt[N]{x_1 \cdot x_2 \cdot x_3 \cdot … x_N}\]The general mathematical expression for the **geometric mean** is:

We can also write the mathematical expression of the **geometric mean** using rational exponents instead of radical:

**Example**: Calculate the **geometric mean** (average) of the monthly minimum temperature for the given set of data.

Month | Minimum temperature [°C] |

January | 2 |

February | 4 |

March | 8 |

April | 13 |

May | 16 |

June | 21 |

July | 23 |

August | 22 |

September | 20 |

October | 17 |

November | 13 |

December | 6 |

We are given 12 measurements of the temperatures, the minimum value for each month. The minimum average temperature for the whole year is the **geometric mean** of the data set:

For a better understanding of the result we are going to plot:

- each monthly minimum temperature as a bar plot
- the
**geometric mean**(yearly minimum average temperature) as a line

As a programming exercise, we’ll write a **Scilab script** which calculates the **geometric mean** for the same set of data:

data_N = [2 4 8 13 16 21 23 22 20 17 13 6]; length_N = length(data_N); prod_N = 1; for i=1:length_N prod_N = prod_N * data_N(i); end x_GM = prod_N^(1/length_N); mprintf("The geometric mean is: %f", x_GM);

For further practicing we are going to write down a **C script** which calculates the **geometric mean** for the same set of data (temperatures):

#include<stdio.h> #include<math.h> int main(void) { double data_N[12] = {2,4,8,13,16,21,23,22,20,17,13,6}; int i; double product_N = 1; double x_GM = 0; double exponent; double length_N = 12; for (i=0;i<length_N;i++){ product_N = product_N * data_N[i]; } exponent = 1/length_N; x_GM = pow(product_N,exponent); printf("The geometric mean is %f: \n",x_GM); return 0; }

For any questions or observations regarding this tutorial please use the comment form below.

Don’t forget to Like, Share and Subscribe!