# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- savePlots = F at = c(-0.3,0.6,0.9,0.2,0.1,-0.6,1.7,-0.9,-1.3,-0.6,-0.4,0.9,0.0,-1.4,-0.6) # a_0, a_1, to a_{14} Na = length(at) Nam1 = Na-1 zt0 = c(19,20) # z_{-1}, z_0 # Part (a): # zt_a = zt0 for( ii in 1:Nam1 ){ # the index of z_t newZ = zt_a[length(zt_a)] + at[ii+1] - 0.5 * at[ii] zt_a = c( zt_a, newZ ) } plot( -1:(length(zt_a)-2), zt_a, col="green", type="l", xlab="index", ylab="z_t", main="Part (a-b)" ) # Part (b): # zt_b = zt0 for( ii in 1:Nam1 ){ # the index of z_t newZ = zt_b[length(zt_b)] + at[ii+1] - 0.2 * at[ii] zt_b = c( zt_b, newZ ) } lines( -1:(length(zt_b)-2), zt_b, col="red", type="l", xlab="index", ylab="z_t", main="Part (a-b)" ) if( savePlots ){ postscript("../../WriteUp/Graphics/Chapter4/prob_3_a_n_b.eps", onefile=FALSE, horizontal=FALSE) plot( -1:(length(zt_a)-2), zt_a, col="green", type="l", xlab="index", ylab="z_t", main="Part (a-b)" ) lines( -1:(length(zt_b)-2), zt_b, col="red", type="l", xlab="index", ylab="z_t", main="Part (a-b)" ) dev.off() } # Part (c): # zt_c = zt0 for( ii in 1:Nam1 ){ # the index of z_t newZ = 1.5*zt_c[length(zt_c)] -0.5*zt_c[length(zt_c)-1] + at[ii+1] zt_c = c( zt_c, newZ ) } plot( -1:(length(zt_c)-2), zt_c, col="green", type="l", xlab="index", ylab="z_t", main="Part (c-d)" ) # Part (d): # zt_d = zt0 for( ii in 1:Nam1 ){ # the index of z_t newZ = 1.2*zt_d[length(zt_d)] -0.2*zt_d[length(zt_d)-1] + at[ii+1] zt_d = c( zt_d, newZ ) } lines( -1:(length(zt_d)-2), zt_d, col="red", type="l", xlab="index", ylab="z_t", main="Part (c-d)" ) if( savePlots ){ postscript("../../WriteUp/Graphics/Chapter4/prob_3_c_n_d.eps", onefile=FALSE, horizontal=FALSE) plot( -1:(length(zt_c)-2), zt_c, col="green", type="l", xlab="index", ylab="z_t", main="Part (c-d)" ) lines( -1:(length(zt_d)-2), zt_d, col="red", type="l", xlab="index", ylab="z_t", main="Part (c-d)" ) dev.off() } # Part (e): # zt_e = zt0 for( ii in 1:Nam1 ){ # the index of z_t newZ = 1.2*zt_e[length(zt_e)] -0.2*zt_e[length(zt_e)-1] + at[ii+1] - 0.5 * at[ii] zt_e = c( zt_e, newZ ) } plot( -1:(length(zt_e)-2), zt_e, xlab="index", ylab="z_t", main="Part (e)" ) lines( -1:(length(zt_e)-2), zt_e ) if( savePlots ){ postscript("../../WriteUp/Graphics/Chapter4/prob_3_e.eps", onefile=FALSE, horizontal=FALSE) plot( -1:(length(zt_e)-2), zt_e, type="l", xlab="index", ylab="z_t", main="Part (e)" ) lines( -1:(length(zt_e)-2), zt_e, type="l", xlab="index", ylab="z_t", main="Part (e)" ) dev.off() }