# Ex 2.18 Finding the root of the charcteristic polynomials z <- seq(-3,3,length=200) a1 <- (-1+sqrt(1+12))/2 a2 <- a1+1 A <- function(z) 1+a1*z+a2*z^2 - z^3 # The characteristic polynomial plot(z,A(z),type="l") uniroot(A,c(2,10)) # Finding the real root z1 <- uniroot(A,c(2,10))$root z <- seq(-2,2,length=200) y <- A(z)/(z-z1) # The quadratic part lm(y~z+I(z^2)) # Fitting the quadratic part b <- lm(y~z+I(z^2))$coef (b[2]^2 + abs(b[2]^2-4*b[1]*b[3]))/(4*b[1]^2) z <- seq(-3,3,length=200) a1 <- (-1-sqrt(1+12))/2 a2 <- a1+1 A <- function(z) 1+a1*z+a2*z^2 - z^3 # The characteristic polynomial plot(z,A(z),type="l") uniroot(A,c(-1,3)) # Finding the real root # Ex 2.23 Plot the autocorrelation functions of MA(p)-processes for different # values of p. ma.autocorr <- function(k,b) { q <- length(b) b <- c(1,b) gamma <- rep(0,k+1) for(s in 0:(min(k,q))) { gamma[s+1] <- sum(b[1:(q-s+1)]*b[(s+1):(q+1)]) } rho <- gamma/gamma[1] return(rho) } k<-10 plot(c(0,k),c(-1,1),type="n",xlab="lag",ylab="rho") lines(0:k,ma.autocorr(k,0.5),type="b") lines(0:k,ma.autocorr(k,c(-0.5,0.3)),type="b",col="red") lines(0:k,ma.autocorr(k,c(0,0.7,-0.2)),type="b",col="blue") lines(0:k,ma.autocorr(k,0.8^(1:7)),type="b",col="green")