------------- # Aufgabe 1 # ------------- # 1a) v1 = c(1.1,3.3,4.56,-7.77) v1 v2 = 1:100 v2 v3 = 2*v2 v3 # oder: v3b = seq(from=2,to=200,by=2) v3b v4 = v3 - 3 v4 v5 = rep(1,100) v5 v6 = rep(c(1,2,3,4),25) v6 v7 = seq(from=500,to=5,by=-5) v7 v7 = seq(500,5,-5) v7 v7 = seq(by=-5,from=500,to=5) v7 v8 = v2*v2 v8 v9 = 1/v8 v9 x = seq(from=0,to=2*pi,length=100) x # 1b) sum(v2*v5) sum(v2*v2) sum(v2*v9) ------------- # Aufgabe 2 # ------------- # 2a) partialsummen = cumsum(v9) partialsummen plot(partialsummen) ?abline abline(a=pi*pi/6,b=0,col="red") # 2b) v=1:1000 v=1/v v sign=(-1)*(-1)^(1:1000) sign v=sign*v v partsum=cumsum(v) plot(partsum) abline(a=log(2),b=0,col="red") # 2c) v=1:100 # 1/0! will be added by hand below v=cumprod(v) v v=1/v partsum=cumsum(v) partsum=partsum+1 # the first term 1/0! = 1 plot(partsum) abline(a=exp(1),b=0,col="red") ------------- # Aufgabe 3 # ------------- # 3a) x = rnorm(1000,mean=15,sd=2) plot(x) hist(x) # 3b) hist(x,breaks=10) hist(x,breaks=20) hist(x,breaks=50) # 3c) hist(x,prob=TRUE) # Die Hoehe der Rechteck-Bloecke in hist(x) sind die absoluten Haeufigkeiten n_abs. # Die Flaeche der Rechteck-Bloecke in hist(x,prob=TRUE) sind die relativen Haeufigkeiten # n_rel = n_abs / n wobei n=1000 die Gesamtzahl der Zufallszahlen ist. Ist also # Delta_x die Breite der Recheck-Bloecke (das muss nicht gleich 1 sein), dann ist die # Hoehe n_prob der Rechteck-Bloecke in hist(x,prob=TRUE) gegeben durch # # n_prob * Delta_x = n_rel oder # # n_prob = n_rel/Delta_x = n_abs / (n*Delta_x) # # Insbesondere ist die Gesamtflaeche in hist(x,prob=TRUE) gleich 1. # 3d) hist(x,prob=TRUE) curve(dnorm(x,mean=15,sd=2),add=TRUE,col="red") # wobei # dnorm(x,mean,sd) = 1/sqrt(2 pi sd^2) * exp(-(x-mean)^2/(2 sd^2))