Trajectory error in phase plane for ODEs in R (PhaseR Package)

41 Views Asked by At

I am trying to plot the trajectory of the ODE in R but I am getting this weird error. I am able to plot the nullclines of the phase plane but I am not able to plot the trajectory of the system. (In my case, the parameters are a and b, but I'm not sure what to do with the function call parameters here. This is from the default function I was given. Should I remove it in the function call?)

PeriodicSystem <- function(t, y, parameters) {
  a <- a
  b <- b
  dx <- -x + (a*y) + ((x^2)*y)
  dy <- b - (a*y) + ((x^2)*y)
  list(c(dx,dy))
}
example4_flowField  <- flowField(PeriodicSystem,
                                 xlim = c(-0.01, .425),
                                 ylim = c(0, .5),
                                 add  = FALSE,
                                 ylab = TeX("$y$"),
                                 xlab= TeX("$x$"),
                                 frac=1,
                                 add.legend=FALSE)
grid()
example4_nullclines <- nullclines(PeriodicSystem,
                                  xlim = c(-0.01, .425),
                                  ylim = c(0, .5),
                                  lty = 2, lwd = 2,
                                  col=c("lightseagreen","aquamarine4"),
                                  add.legend=FALSE)

example4_flowField  <- flowField(PeriodicSystem,
                                 xlim = c(-0.01, .425),
                                 ylim = c(0, .5),
                                 add  = FALSE,
                                 ylab = TeX("$y$"),
                                 xlab= TeX("$x$"),
                                 frac=1,
                                 add.legend=FALSE)
grid()
example4_nullclines <- nullclines(PeriodicSystem,
                                  xlim = c(-0.01, .425),
                                  ylim = c(0, .5),
                                  lty = 2, lwd = 2,
                                  col=c("lightseagreen","aquamarine4"),
                                  add.legend=FALSE)

y0 <- matrix(c(0.1,0.3,
               0,0,
               0.1,0.2), 3, 2, byrow = TRUE)
example4_trajectory <- trajectory(PeriodicSystem,
                                  y0   = y0,
                                  pch=16,
                                  tlim = c(0, 100),
                                  col="black",
                                  add=T, ylab=TeX("$x, y$"), xlab=TeX("$t$"))
grid()

Note: col has been reset as required
Error in checkFuncEuler(Func, times, y, parms, rho, Nstates) : 
  The number of derivatives returned by func() (1000must equal the length of the initial conditions vector (2)
0

There are 0 best solutions below