2.3 Using R or Matlab to do the exercises.

The best (and easiest) way to simulate these simple models is to create a function which takes as input the parameters (\(Y_0\), \(r\)) and a variable indicating the length of the time series.

For example for the Linear Map:

# In R
linearMap <- function(Y0 = 0, r = 1, N = 100){
    # Initialize Y as an NA vector of size N with as first entry Y0
    Y <- c(Y0, rep(NA,N-1))
    for(i in 1:N){
    Y[i+1] <- # Implement the function here

# In Matlab
function linearMap(Y0,r,N)
 # Implement the function here

Creating the time series graphs and the return plot should be easy if the function linearMap returns the time series. Both R and Matlab have a plot() function you can call.1

  1. Both R and Matlab have specialized objects to represent timeseries, and functions and packages for timeseries analysis. They are especially convenient for plotting time and date information on the X-axis. See Solutions: Mathematics of Change I