Ich habe einen 2D-Gaussian (ohne Korrelation zwischen den unabhängigen Variablen) mit den Parametern Area, Sigmax und Sigmay definiert. Wenn ich eine Integration von (inf, inf) in beiden Variablen ich die Gegend erhalten nur, wenn Sigmax und sigmay sind 1.Integration der 2d-Gauss-Funktion (Python)
import numpy as np
import scipy.integrate as sci
class BeamDistribution(object):
def __init__(self, Ipeak, sigmax, sigmay):
print Ipeak, sigmax, sigmay
self.__Ipeak = Ipeak
self.__sigmax = sigmax
self.__sigmay = sigmay
def value(self, x, y):
factor = self.__Ipeak/(2.*np.pi*self.__sigmax * self.__sigmay)
factorx = np.exp(-x**2/(2.*self.__sigmax**2))
factory = np.exp(-y**2/(2.*self.__sigmay**2))
return factor*factorx*factory
def integral(self, a, b, c, d):
integration = sci.dblquad(self.value, a, b, lambda x: c, lambda x: d,
epsrel = 1e-9, epsabs = 0)
# sci.quad_explain()
return integration
def __call__(self, x, y):
return self.value(x, y)
if __name__ == "__main__":
Ipeak = 65.0e-3
sigmax = 0.2e-3
sigmay = 0.3e-3
limit = np.inf
my_beam_class = BeamDistribution(Ipeak, sigmax, sigmay)
total = my_beam_class.integral(-limit, limit, -limit, limit)
print "Integrated total current ",total," of Ipeak ", Ipeak
my_beam_class = BeamDistribution(Ipeak, 1, 1)
total = my_beam_class.integral(-limit, limit, -limit, limit)
print "Integrated total current ",total," of Ipeak ", Ipeak
Der Ausgang ist
0.065 0.0002 0.0003
Integrated total current (7.452488478001055e-32, 6.855160478762106e-41) of Ipeak 0.065
0.065 1 1
Integrated total current (0.4084070449667172, 1.0138233535120856e-11) of Ipeak 0.065
Jede Idee, warum das so ist Ereignis? Ich denke, es sollte etwas Einfaches sein, aber nach Stunden, wenn ich darauf schaue, kann ich nichts falsches sehen.
gute Methode; Kannst du es für 2D Gaussian verallgemeinern, wie in der Frage? – JPG
@JPG Fertig ...... –
Gut, danke! Ich war mir nicht sicher, ob es so geradlinig war oder nicht. – JPG