Normalverteilung Dichtefunktion
Verfasst: Donnerstag 1. Februar 2018, 16:12
Mein Problem ist, dass ich ein Programm schreiben will dass die Dichte berechnet, jedoch gibt es immer falsche Ergebnisse und ich konnte keinen Fehler finden.
Ich wäre sehr dankbar wenn mir jemand auf die Sprünge helfen könnte.
LG nono
Code: Alles auswählen
import math
import scipy.stats as stats
class NormalDistribution:
def __init__(self, mu, sigma_square):
self.mu = mu
self.sigma = math.sqrt(sigma_square)
def pdf(self, x):
return 1 / (self.sigma * math.sqrt(2 * math.pi)) * math.exp(-(math.pow(x - self.mu, 2) / (2 * math.pow(self.sigma, 2))))
print(NormalDistribution(0, 3).pdf(1))
print(stats.norm.pdf(1, 0, 3))
Code: Alles auswählen
Output:
0.19496965572274114 # Ausgabe des Programms
0.12579440923099774 # Korrekte Ausgabe
LG nono