A Rate Problem that can be solved with Harmonic Mean¶
Leslie drives X miles due north at 15 mph, then drives X miles due west at 30 mph, then drives X miles due south at 45 mph, then drives X miles due east at 50 mph, and arrives back at her starting point. What was Leslie's average speed for the trip?
The total distance driven is 4X. The time taken to drive the first leg was X/15 hours. Similarly, the other legs took X/30, X/45, and X/50 hours. Therefore,
$Average\ Speed\ =\frac{Total\ Distance}{Total\ Time}=\frac{4X}{\frac{X}{15}+\frac{X}{30}+\frac{X}{45}+\frac{X}{50}}$
The X's in the numerator and denominator cancel.
$Average\ Speed\ =\frac{4}{\frac{1}{15}+\frac{1}{30}+\frac{1}{45}+\frac{1}{50}}$
4/(1/15+1/30+1/45+1/50)
This is the harmonic mean of the four speeds. The same result could be obtained with the hmean() function.
from scipy.stats.mstats import *
hmean([15,30,45,50])
A Problem that uses Geometric Mean¶
Leslie has staked out a rectangular plot of land measuring 6 meters by 15 meters for a garden. Then she decides to change the shape of her garden to be a square, but she would like it to have the identical area as the original rectangular garden. What should be the side length of the new square-shaped garden?
The original garden had an area of 6x15 square meters.
6*15
A square with this area would have side length sqrt(90)
import math
math.sqrt(90)
This is the geometric mean of the two lengths. The same result could be obtained with the gmean() function.
gmean([6,15])
A few calculations with Complex Numbers¶
a=2+3j
a.real
a.imag
b=-4+5j
a+b
a-b
a*b
a/b
For Complex Numbers, use cmath functions
import cmath
cmath.exp(-3-1j)
cmath.sqrt(-3)