--------------- # Aufgabe 2 # --------------- # Wir codieren eine Funktion, die zu vorgegebenem # f das Integral # # 1/(2*pi*i) int_{C_r(z0)} f(z) dz # # berechnet, wobei C_r(z0) ein Kreis mit Radius # r um z0 ist: IntC = function( f , z0 , r ) { n = 100000 # Fehler = O(1/n) -> bis auf # 5 oder 6 Stellen genau phi = seq(from=0,to=2*pi,length=n) z = z0 + r*exp(1i*phi) dz = diff(z) z = z[-1] integral = sum( f(z) * dz ) * 1/(2*pi*1i) return(integral) } # Wir muessen die folgenden Funktionen numerisch # integrieren: fa1 = function(z) { return( sin(z)/z ) } fa2 = function(z) { return( sin(z)/z^2 ) } fa3 = function(z) { return( sin(z)/z^3 ) } fa4 = function(z) { return( sin(z)/z^4 ) } fb = function(z) { return( 1/(z*cos(z)) ) } fc = function(z) { return( 1/(1-z^2) ) } fd = function(z) { return( 1/(1-z^2)^2 ) } fe = function(z) { return( sqrt(4+z)/z ) } ff = function(z) { return( log(z)/(z-1i) ) } # Jetzt koennen wir integrieren: IntC( f=fa1 , z0=0 , r=1 ) # -3.372718e-17-8.0512e-19i ist eine numerische 0 IntC( f=fa2 , z0=0 , r=1 ) # 1-0.0000314i -> 1 IntC( f=fa3 , z0=0 , r=1 ) # -3.190455e-17+1.43371e-18i ist eine numerische 0 IntC( f=fa4 , z0=0 , r=1 ) # -0.1666667+0.0000052i -> -1/6 IntC( f=fb , z0=0 , r=1 ) # 1-0.0000314i -> 1 IntC( f=fc , z0=1 , r=1 ) # -0.5+0.0000157i -> -1/2 IntC( f=fd , z0=1 , r=1 ) # -0.25+0.0000079i -> -1/4 IntC( f=fe , z0=1 , r=2 ) # 2-0.000063i -> 2 IntC( f=ff , z0=3*1i/2 , r=1 ) # 0.000049+1.570796i -> pi/2 i --------------- # Aufgabe 4 # --------------- # START Beispiele Contour- und 3D-Plots: # # function of 2 variables to be plotted: testf = function(x,y) { result = (-x^2+y^2)*exp(-0.25*x^2-0.5*y^2) return(result) } # the contour()-command has syntax # contour( vector , vector , matrix ) = # contour( x-Achse , y-Achse , f(x,y) ) x = seq(from=-4,to=4,by=0.1) y = x # matrix with testf(x,y)-values: z = outer( x , y , FUN = testf ) # and now the level curves: contour( x , y , z ) contour( x , y , z , nlevels=50 ) # more refined # also useful: image( x , y , z ) persp( x , y , z ) # with plot3D package, to be installed: require(plot3D) persp3D( x , y , z ) # ENDE Beispiele Contour- und 3D-Plots # Zurueck zur Funktion h(z) aus Aufgabe 4: # Wir machen einen Plot von |h(z)|: x = seq(from =-0.1, to=0.1, by=0.025) y = x nx = length(x) ny = nx absh = matrix(0,nrow=nx,ncol=ny) for(i in 1:nx) { for(j in 1:ny) { z = x[i]+1i*y[j] if(abs(z)>0) absh[i,j] = abs(exp(-1/z^2)) else absh[i,j] = 0 } } contour(x,y,absh) contour(x,y,absh,nlevels=100) contour(x,y,absh,nlevels=100,zlim=c(0,2)) contour(x,y,absh,nlevels=100,zlim=c(10^(10),10^(11))) persp(x,y,absh) # error: invalid z-limits.. absh = pmin(absh,1000) # 'parallel min': elementweise genommen, # min(absh,1000) ist eine Zahl, keine # Matrix mehr persp(x,y,absh) image(x,y,absh) contour(x,y,absh,nlevels=100) # install package plot3D and then: require(plot3D) persp3D(x,y,absh)