ts = seq( -1, 1, length.out=100 ) phi_1 = - ts phi_2 = ts^2 / 2 - ts phi_3 = - ts^3 / 6 + ts^2 / 2 - ts phi_4 = ts^4 / 24 - ts^3 / 6 + ts^2 / 2 - ts phi_inf = exp(-ts) - 1 all_phis = c( phi_1, phi_2, phi_3, phi_4, phi_inf ) all_phi_errors = c( phi_1 - phi_inf, phi_2 - phi_inf, phi_3 - phi_inf, phi_4 - phi_inf ) all_phi_abs_errors = abs(all_phi_errors) #postscript("../../WriteUp/Graphics/Chapter2/chap_2_sect_8_prob_4_plot.eps", onefile=FALSE, horizontal=FALSE) par(mfrow=c(1,2)) # The functions: # min_y = min( all_phis ) max_y = max( all_phis ) plot( ts, phi_1, type='l', ylim=c( min_y, max_y ), col='red', xlab='t', ylab='phi_n(t)' ) lines( ts, phi_2, type='l', col='blue' ) lines( ts, phi_3, type='l', col='green' ) lines( ts, phi_4, type='l', col='darkblue' ) lines( ts, phi_inf, type='l', col='black' ) legend( 'topleft', c('phi_1(t)', 'phi_2(t)', 'phi_3(t)', 'phi_4(t)', 'phi(t)'), lwd=2, lty=1, col=c('red', 'blue', 'green', 'darkblue', 'black')) grid() # The errors: # min_y = min( all_phi_abs_errors ) max_y = max( all_phi_abs_errors ) plot( ts, abs(phi_inf - phi_1), type='l', ylim=c( min_y, max_y ), col='red', xlab='t', ylab='|phi(t) - phi_n(t)|' ) lines( ts, abs(phi_inf - phi_2), type='l', col='blue' ) lines( ts, abs(phi_inf - phi_3), type='l', col='green' ) lines( ts, abs(phi_inf - phi_4), type='l', col='darkblue' ) legend( 'topleft', c('phi_1 aerr', 'phi_2 aerr', 'phi_3 aerr', 'phi_4 aerr'), lwd=2, lty=1, col=c('red', 'blue', 'green', 'darkblue')) grid() par(mfrow=c(1,1)) #dev.off()