---------------- # Aufgabe 3b # ---------------- # wir approximieren das Integral durch eine # Riemannsche Summe von -xmax bis xmax mit # Schrittweite dx: xmax = 20 dx = 0.001 x = seq(from=-xmax,to=xmax,by=dx) # wir plotten das Integral fuer festes aber # variables alpha als Funktion von k fuer # k = -5.0, -4.9, ... , 4.9 , 5.0: alpha = 2 k = seq(from=-5.0,to=5.0, by=0.1) # exaktes Resultat: exact = function( k , alpha ) { res = 1/sqrt(alpha) * exp(-1/alpha*k^2/2) return(res) } curve(exact(x,alpha),from=-5,to=5) # Riemannian sums: for(kk in k) { integrand = exp(1i*kk*x)*exp(-alpha*x^2/2) riemannsum = sum(integrand)*dx/sqrt(2*pi) # add result to previous plot: since the # result is complex, we plot the real and # imaginary part: points(kk,Re(riemannsum),col="red") points(kk,Im(riemannsum),col="green") }