Problem in defining a system of differential equations

I have a system of ODE in matrix form with initial condition:

formula

condition

C is user defined diagonal matrix

Theta is column vector

Lambda is user defined matrix

P is user defined vector

I’m tried define ODE system by this code:

using LinearAlgebra, DifferentialEquations

Λ = [34.27 0 -22.22 0 -12.05 0 0 0;
    0 45.57 0 -26.05 0 -19.52 0 0;
    -22.22 0 66.22 -4 0 0 0 -40;
    0 -26.05 -4 39.49 0 0 -8.333 -1.103;
    -12.05 0 0 0 22.05 0 -10 0;
    0 -19.52 0 0 0 33.81 -14.29 0;
    0 0 0 -8.333 -10 -14.29 39.29 -6.667;
    0 0 -40 -1.103 0 0 -6.667 69.77;
]
C = [1977, 1034, 9390, 14820, 3196, 1426, 20.5, 15840]
C = diagm(C)
P = [272.25, 103.95, 312.567, 70.567, 332.75, 127.05, 0, 0]
 function ODEsys(u,p,t)
    inv(C) * (P - Λ)
 end

θ₀ = rand(8, 2)
 timespan = (0, 1)
 prob = ODEProblem(ODEsys, θ₀, timespan)
 sol = solve(prob)

but it didn’t work, i get an error:
ERROR: DimensionMismatch: arrays could not be broadcast to a common size; got a dimension with lengths 8 and 2
what i did wrong?

P is a vector bu Λ is a matrix.

Also, you function ODEsys does not depend on \theta like your equation does. Try this

function ODEsys(u,p,t)
  inv(C) * (P - Λ*u)
end
1 Like