--------------- # Aufgabe 1 # --------------- # 1a) n = 1000 m = 8 x = seq(from=-1,to=1,length=n) # 1b) X = x for(k in 2:m) { X = cbind(X,x^k) } head(X) # let's put some names on: colnames(X) = c("x","x^2","x^3","x^4","x^5","x^6","x^7","x^8") head(X) # 1c) y = exp(x) res = lm(y ~ X) summary(res) # 1d) betas = res$coeff betas k = 0:m plot(k,factorial(k)*betas) # looks a bit odd on first sight, # however, let's change the scale # of y-axis: plot(k,factorial(k)*betas, ylim=c(0,2)) # thus: beta[k] = 1/k! , is ok. # 1e) plot(x,y,type="l") lines(x,res$fit,col="red") --------------- # Aufgabe 2 # --------------- # 2a) e^x = 1 + x + x^2/2 + O(x^3), also e^(x-y) = 1 + x-y + (x-y)^2/2 + higher order = 1 + x - y + x^2/2 - 2xy/2 + y^2/2 + higher order, also: a=1, b1=1, b2=0.5, c1=-1, c2=0.5, d=-1 # 2b) n = 1000 x = runif(n,min=-0.1,max=0.1) y = runif(n,min=-0.1,max=0.1) # Matrix von Regressoren: X = cbind(x,x^2,y,y^2,x*y) # dieselbe Reihenfolge wie in 2a f = exp(x-y) res = lm( f ~ X) betas = res$coeff betas # in derselben Reihenfolge wie in 2a angegeben