Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In the introduction to the time series course (MAT8181) this morning, we did spend some time on the expression of (deterministic) sequences defined using a linear recurence (we will need that later on, so I wanted to make sure that those results were familiar to everyone).
- First order recurence
The most simple case is the first order recurence,
- Second order recurence
Consider now a second order recurence,
> a=.5 > b=-.9 > u1=1; u0=1
Then, we iterate to generate the sequence,
> v=c(u1,u0) > while(length(v)<100) v=c(a*v[1]+b*v[2],v) > plot(0:99,rev(v))
> r=polyroot(c(-b, -a, 1)) > r [1] 0.25+0.9151503i 0.25-0.9151503i > plot(r,xlim=c(-1.1,1.1),ylim=c(-1.1,1.1),pch=19,col="red") > u=seq(-1,1,by=.01) > lines(u,sqrt(1-u^2),lty=2) > lines(u,-sqrt(1-u^2),lty=2)
> A=sum( solve(matrix(c(1,r[1],1,r[2]),2,2),c(u0,u1))) > B=diff(solve(matrix(c(1,r[1],1,r[2]),2,2),c(u0,u1)))* complex(real=0,imaginary=1)
We can plot the sequence of points
> plot(0:99,rev(v))
and then we can also plot the sine wave, too
> t=seq(0,100,by=.1) > lines(t,Vectorize(bv)(t-1),col="red",lty=2) > lines(t,-Vectorize(bv)(t-1),col="red",lty=2) > lines(t,Vectorize(fv)(t-1),col="blue")
We will see a lot of graph like this in the course, when looking at autocorrelation functions.
- Higher order recurence
More generally, we can write
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.