# Problem in defining a system of differential equations

**URL:** <https://discourse.julialang.org/t/problem-in-defining-a-system-of-differential-equations/100536>\
**Category:** New to Julia\
**Tags:** ode, differentialequation\
**Created:** [June 18, 2023, 11:51pm UTC](https://discourse.julialang.org/t/problem-in-defining-a-system-of-differential-equations/100536 "2023-06-18T23:51:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enc](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@Enc](https://discourse.julialang.org/u/Enc)\
**Post date:** [June 18, 2023, 11:51pm UTC](https://discourse.julialang.org/t/problem-in-defining-a-system-of-differential-equations/100536/1 "2023-06-18T23:51:30Z")

</div>

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

![formula](https://latex.codecogs.com/svg.image?%5CLARGE&space;C%5Cfrac%7B%5Cmathrm%7Bd%7D%5Ctheta%7D%7B%5Cmathrm%7Bd%7Dt%7D+%5CLambda%5Ctheta=P)

![condition](https://latex.codecogs.com/svg.image?%5CLARGE%5Ctheta(t_0)&space;=&space;%5Ctau_0)

C is user defined diagonal matrix

![Theta](https://latex.codecogs.com/svg.image?%5CTheta) is column vector

![Lambda](https://latex.codecogs.com/svg.image?%5CLambda) is user defined matrix

P is user defined vector

I’m tried define ODE system by this code:

```julia
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?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [June 19, 2023, 6:41am UTC](https://discourse.julialang.org/t/problem-in-defining-a-system-of-differential-equations/100536/2 "2023-06-19T06:41:01Z")

</div>

> [@Enc](#):
>
> `P - Λ`

`P` is a vector bu `Λ` is a matrix.

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

```julia
function ODEsys(u,p,t)
  inv(C) * (P - Λ*u)
end
```
