3
votes

So I want to ask whether there's any way to define and solve a system of differential equations in R using matrix notation.

I know usually you do something like

lotka-volterra <- function(t,a,b,c,d,x,y){
    dx <- ax + bxy
    dy <- dxy - cy
    return(list(c(dx,dy)))
}

But I want to do

lotka-volterra <- function(t,M,v,x){
    dx <- x * M%*% x + v * x
    return(list(dx))
}

where x is a vector of length 2, M is a 2*2 matrix and v is a vector of length 2. I.e. I want to define the system of differential equations using matrix/vector notation.

This is important because my system is significantly more complex, and I don't want to define 11 different differential equations with 100+ parameters rather than 1 differential equation with 1 matrix of interaction parameters and 1 vector of growth parameters.

I can define the function as above, but when it comes to using ode function from deSolve, there is an expectation of parms which should be passed as a named vector of parameters, which of course does not accept non-scalar values.

Is this at all possible in R with deSolve, or another package? If not I'll look into perhaps using MATLAB or Python, though I don't know how it's done in either of those languages either at present.

Many thanks,

H

1

1 Answers

0
votes

With my low reputation (points), I apologize for posting this as an answer which supposedly should be just a comment. Going back, have you tried this link? In addition, in an attempt to find an alternative solution to your problem, have you tried MANOPT, a toolbox of MATLAB? It's actually open source just like R. I encountered MANOPT on a paper whose problem boils down to solving a system of ODEs involving purely matrices.