I’m trying to define a system of differential equations using matrix notation. The issue is that this matrix varies depending on the problem and in all the examples that I’ve seen the function f that goes in the ODEProblem() function, only has the three variables f(u,p,t).
In the following example, I want to define a function for which I can change the value that defines the size of the identity matrix (A):
using DifferentialEquations
using LinearAlgebrape or paste code here
function f(u,p,t)
A = I(4)
p[1].*(A*u).*(1/t^(1+p[2]))
end
u0 = [0.1,0.3,0.5,0.8]
p = [5.5, 0.5];
As you can deduct, I’m using the matrix A to define 4 different state variables. Each state variable will be defined by the same parameters, but the initial state of each variable is different.
tspan = (3.0,30.0)
prob = ODEProblem(f,u0,tspan,p)
Age1 = collect(5:5:30)
sol = solve(prob, saveat=Age1); #you can plot this for clarity
Ideally, I want something like this:
n = 4
function f(u,p,t,n)
A = I(n)
p[1].*(A*u).*(1/t^(1+p[2]))
end
I know this doesn’t work, but any ideas of how I can modify the code so it admits different sizes for the matrix A?
Thanks!