# Create a out-of-place form for ODE over than 1 function

**URL:** <https://discourse.julialang.org/t/create-a-out-of-place-form-for-ode-over-than-1-function/100155>\
**Category:** Community\
**Tags:** question, ode, function, neural-network\
**Created:** [June 11, 2023, 2:22am UTC](https://discourse.julialang.org/t/create-a-out-of-place-form-for-ode-over-than-1-function/100155 "2023-06-11T02:22:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)\
**Post date:** [June 11, 2023, 2:22am UTC](https://discourse.julialang.org/t/create-a-out-of-place-form-for-ode-over-than-1-function/100155/1 "2023-06-11T02:22:01Z")

</div>

The tutorial of neuralPDE to solve the ODE system just has a simple function, and the optimizer just supports out-of-place form only. How could implement the ODE system with 2 or more functions? For example.

> du[1] = cos(u[1] - u[2])  
> du[2] = sin(u[2] - u[1])

Furthermore, does NeuralPDE can solve the ODE system which transfer from DAEs system?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 11, 2023, 3:44am UTC](https://discourse.julialang.org/t/create-a-out-of-place-form-for-ode-over-than-1-function/100155/2 "2023-06-11T03:44:47Z")

</div>

Just output an array:

```julia
function f(u,p,t)
  [cos(u[1] - u[2]),sin(u[2] - u[1])]
end

```

> [@Ethan\_Tran](#):
>
> Furthermore, does NeuralPDE can solve the ODE system which transfer from DAEs system?

Not automatically. For now you’d have to use PDESystem, though doing something for DAEs is not out of the question.

---

<div class="post-metadata">

**Author:** ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)\
**Post date:** [June 11, 2023, 4:08am UTC](https://discourse.julialang.org/t/create-a-out-of-place-form-for-ode-over-than-1-function/100155/3 "2023-06-11T04:08:29Z")

</div>

I used the code following:

```julia
using NeuralPDE, Flux, OptimizationOptimisers

function f(u,p,t)
  [cos(u[1] - u[2]),sin(u[2] - u[1])]
end
tspan = (0.0f0, 1.0f0)
u0 = [0.0f0, 0.0f0]
prob = ODEProblem(f, u0, tspan)

chain = Flux.Chain(Dense(2, 10, sigmoid), Dense(10, 2))

opt = OptimizationOptimisers.Adam(0.1)

sol = solve(prob, NeuralPDE.NNODE(chain, opt), verbose=true, abstol=1f-6, maxiters=200)

```

However, I got the message:

> DimensionMismatch: Dimensions of the initial u0 and chain should match.

Please help me with this error.

For the PDESystem, in all tutorials I saw that it requires the boundary conditions. How could I use it without boundary conditions? Because the system do not have the boundary.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 11, 2023, 5:01am UTC](https://discourse.julialang.org/t/create-a-out-of-place-form-for-ode-over-than-1-function/100155/4 "2023-06-11T05:01:09Z")

</div>

> [@Ethan\_Tran](#):
>
> ```julia
> chain = Flux.Chain(Dense(2, 10, sigmoid), Dense(10, 2))
> 
> ```

should be `chain = Flux.Chain(Dense(1, 10, sigmoid), Dense(10, 2))` since the number of independent variables is always 1 for an ODE. That should get a better error message.

> [@Ethan\_Tran](#):
>
> For the PDESystem, in all tutorials I saw that it requires the boundary conditions. How could I use it without boundary conditions? Because the system do not have the boundary.

For DAE, the boundary condition is the initial condition.

---

<div class="post-metadata">

**Author:** ![Ethan\_Tran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethan_tran/32/49198_2.png) [@Ethan\_Tran](https://discourse.julialang.org/u/Ethan_Tran)\
**Post date:** [June 12, 2023, 6:05pm UTC](https://discourse.julialang.org/t/create-a-out-of-place-form-for-ode-over-than-1-function/100155/5 "2023-06-12T18:05:04Z")

</div>

Would you please provide me with some documents to create DAE on the PDE system?  
Because I have one independent variable (a problem in 1 dimension) and 45 dependent variables, and I do not think the only way is to type all the variables but I can not find any instruction for that.  
For example, I have 9 variables x and y variables y, I think the default method to implement is:

```julia
@parameters t
@variables x1(..) x2(..) x3(..) y1(..) y2(..) y(..)
Dx1 = Differential(t)
Dx2 = Differential(t)
Dx3 = Differential(t)

```

Thank you for your time and consideration.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 13, 2023, 3:14am UTC](https://discourse.julialang.org/t/create-a-out-of-place-form-for-ode-over-than-1-function/100155/6 "2023-06-13T03:14:43Z")

</div>

> [@Ethan\_Tran](#):
>
> and I do not think the only way is to type all the variables but I can not find any instruction for that.  
> For example, I have 9 variables x and y variables y, I think the default method to implement is:

No I’m suggesting just write down the equations. A DAE is a 1-dimensional PDE.
