if( !require('phaseR') ){ install.packages('phaseR') } library(phaseR) save_plots = FALSE diff_eq_params = list(alpha=2.0) # The critical points of this system: # CP = data.frame( x=c(1, 2), y=c(3, 4)) my_jacobian = function(x, y, parameters=diff_eq_params) { # returns the Jacobian at the point (x, y) # J = matrix(c(-1, 1, -4 + 2*x, 1), nrow=2, ncol=2, byrow=TRUE) } As = mapply(my_jacobian, CP$x, CP$y, SIMPLIFY=FALSE) for (ii in 1:length(As)){ es = eigen(As[[ii]]) print(sprintf('CP: x= %f; y= %f', CP$x[ii], CP$y[ii])) print('Jacobian=') print(As[[ii]]) print('eigenvalues=') print(es$values) } my_yprime = function(t, y, parameters) { xt = y[1] yt = y[2] dy = rep(NA, length(y)) dy[1] = -parameters$alpha - yt + xt dy[2] = -4*xt + yt + xt^2 list(dy) } # Part (c): # if( save_plots ){ postscript('../../WriteUp/Graphics/Chapter9/chap_9_sect_4_prob_16_plot.eps', onefile=FALSE, horizontal=FALSE) } par(mfrow=c(1, 3)) t.end = 5.0 flowField(my_yprime, x.lim = c(0, +4), y.lim = c(0, +6), parameters = diff_eq_params, points = 30, add = FALSE, xlab='x', ylab='y', main=sprintf('alpha= %.3f', diff_eq_params$alpha)) # Plot some trajectories with initial condition near the critical points: # trajectory(my_yprime, y0 = c(2, 5), t.end = t.end, parameters = diff_eq_params, col='black', pch=8) trajectory(my_yprime, y0 = c(3.5, 4.0), t.end = t.end, parameters = diff_eq_params, col='blue', pch=8) trajectory(my_yprime, y0 = c(2, 1.0), t.end = t.end, parameters = diff_eq_params, col='red', pch=8) trajectory(my_yprime, y0 = c(3, 1.0), t.end = t.end, parameters = diff_eq_params, col='green', pch=8) points(CP$x, CP$y, pch=19) # Part (d): # alpha_0 = 9/4 diff_eq_params = list(alpha=alpha_0) CP = data.frame( x=c(2), y=c((3/2)*alpha_0)) t.end = 5.0 flowField(my_yprime, x.lim = c(0, +4), y.lim = c(0, +6), parameters = diff_eq_params, points = 30, add = FALSE, xlab='x', ylab='y', main=sprintf('alpha= alpha_0= %.3f', alpha_0)) # Plot some trajectories with initial condition near the critical points: # trajectory(my_yprime, y0 = c(2, 5), t.end = t.end, parameters = diff_eq_params, col='black', pch=8) trajectory(my_yprime, y0 = c(3.5, 4.0), t.end = t.end, parameters = diff_eq_params, col='blue', pch=8) trajectory(my_yprime, y0 = c(2, 1.0), t.end = t.end, parameters = diff_eq_params, col='red', pch=8) trajectory(my_yprime, y0 = c(3, 1.0), t.end = t.end, parameters = diff_eq_params, col='green', pch=8) points(CP$x, CP$y, pch=19) # Part (e): # alpha = 3 diff_eq_params = list(alpha=alpha) t.end = 5.0 flowField(my_yprime, x.lim = c(0, +4), y.lim = c(0, +6), parameters = diff_eq_params, points = 30, add = FALSE, xlab='x', ylab='y', main=sprintf('alpha= %.3f', alpha)) # Plot some trajectories with initial condition near the critical points: # trajectory(my_yprime, y0 = c(2, 5), t.end = t.end, parameters = diff_eq_params, col='black', pch=8) trajectory(my_yprime, y0 = c(3.5, 4.0), t.end = t.end, parameters = diff_eq_params, col='blue', pch=8) trajectory(my_yprime, y0 = c(2, 1.0), t.end = t.end, parameters = diff_eq_params, col='red', pch=8) trajectory(my_yprime, y0 = c(3, 1.0), t.end = t.end, parameters = diff_eq_params, col='green', pch=8) if( save_plots ){ dev.off() } par(mfrow=c(1, 1))