In [1]:
%matplotlib inline

import cmath
from matplotlib.pylab import *
tau = 2 * cmath.pi
    
def mittelwert(werte):
    base = cmath.e ** (1j * tau / 360)
    total = 0
    for wert in werte:
        v = wert[1] * base ** wert[0]
        total += v
        arrow(0,0,v.real,v.imag,head_width=0.05,head_length=0.05,fc='r',ec='r')
    result = total / len(werte)
    arrow(0,0,result.real,result.imag,head_width=0.05,head_length=0.05,fc='b',ec='b')
    xlim((-1.5,1.5))
    ylim((-1.5,1.5))
    xlabel('Real')
    ylabel('Imaginaer')
    return (cmath.log(result,base).real, abs(result))

In [2]:
mittelwert(((12,1),(15,1),(13,1),(9,1),(16,1)))


Out[2]:
(13.00030477988622, 0.9990864214521126)

In [3]:
mittelwert(((358,1),(1,1),(359,1),(355,1),(2,1)))


Out[3]:
(-0.9996952201137815, 0.999086421452112)

In [4]:
mittelwert(((210,1),(290,1),(10,1),(90,1),(170,1)))


Out[4]:
(-170.00000000000048, 0.10641777724759095)

In [5]:
mittelwert(((170,1),(171,1),(180,1),(181,1),(190,1)))


Out[5]:
(178.3940374169937, 0.9918198913259431)

In [ ]:


In [ ]: