WT-Übung 6 - Aufgabe 24

Erzeugung von normalverteilten ZVs aus gleichverteilten:


In [1]:
%matplotlib inline
import numpy as np; from numpy import pi, log, sin, cos, sqrt, exp
from matplotlib.pyplot import figure

def plot_dist(samples, density, subplot=121):
    ax = fig.add_subplot(subplot)
    _, bins, _ = ax.hist(samples, bins=50, normed=True)
    ax.plot(bins, density(bins), 'r-')
    return ax

Gegebene Zufallsvariablen: $U_1$ und $U_2$


In [2]:
N = 10000
sigma = 3

u1, u2 = np.random.rand(N), np.random.rand(N)

def equal(x_min=0, x_max=1):
    """Dichte einer Gleichverteilung"""
    return lambda x: np.ones_like(x) / (x_max - x_min)

fig = figure(figsize=(14, 6), facecolor='w')
plot_dist(u1, equal(0, 1), subplot=121)
plot_dist(u2, equal(0, 1), subplot=122);


Zufallsvariablen: $R$ und $\Phi$


In [3]:
r = sigma * sqrt(-2 * log(1 - u1))
phi = 2*pi * u2

def rayleigh(sigma):
    """Dichte einer Reyleighverteilung"""
    return lambda x: x / sigma**2 * exp(-x**2 / sigma**2 / 2)

fig = figure(figsize=(14, 6), facecolor='w')
plot_dist(r, rayleigh(sigma), subplot=121)
plot_dist(phi, equal(0, 2*pi), subplot=122);


Gesuchte Zufallsvariablen: $X$ und $Y$


In [4]:
x = r * cos(phi)
y = r * sin(phi)

def gauss(mu, sigma):
    """Dichte einer Normalverteilung"""
    return lambda x: exp(-((x - mu) / sigma)**2 / 2) / sqrt(2*pi) / sigma

fig = figure(figsize=(14, 6), facecolor='w')
plot_dist(x, gauss(0, sigma), subplot=121)
plot_dist(y, gauss(0, sigma), subplot=122);