if( !require('phaseR') ){ install.packages('phaseR') } library(phaseR) # The critical points of this system: # CP = data.frame( x=c(0, 0.5), y=c(0, 2) ) my_jacobian = function(x, y) { # returns the Jacobian at the point (x, y) # J = matrix(c(1.0 - 0.5*y, -0.5*x, 0.5*y, -0.25 + 0.5*x), 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] = xt*(1 - 0.5*yt) dy[2] = yt*(-0.25 + 0.5*xt) list(dy) } diff_eq_params = list() #postscript('../../WriteUp/Graphics/Chapter9/chap_9_sect_5_prob_2_plot.eps', onefile=FALSE, horizontal=FALSE) t.end = 10.0 flowField(my_yprime, x.lim = c(-0.1, 2.0), y.lim = c(-0.1, 5), parameters = diff_eq_params, points = 30, add = FALSE, xlab='x', ylab='y') # Plot some trajectories with initial condition near the critical points: # trajectory(my_yprime, y0 = c(0.1, 4), t.end = t.end, parameters = diff_eq_params, col='black', pch=8) trajectory(my_yprime, y0 = c(1, 3), t.end = t.end, parameters = diff_eq_params, col='blue', pch=8) trajectory(my_yprime, y0 = c(1, 1), t.end = t.end, parameters = diff_eq_params, col='red', pch=8) points(CP$x, CP$y, pch=19) #dev.off()