# ODE with vector Argument

**URL:** <https://discourse.julialang.org/t/ode-with-vector-argument/64918>\
**Category:** New to Julia\
**Created:** [July 19, 2021, 10:28am UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918 "2021-07-19T10:28:46Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 19, 2021, 10:28am UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/1 "2021-07-19T10:28:46Z")

</div>

Dear Friends

I am trying to solve an ode problem function myfun(du,u,p,t)

where u consists of the vectors x,z,e. I want this function return solution just for e  
(I do not know how must I do this)

Here is the code which I have used for it

using DifferentialEquations  
using LinearAlgebra  
using Plots  
function myfun(du,u,p,t)  
x, z, e = u  
du[1] = dx[1] = x[2]  
du[2] = dx[2] = -p[1]^2\*((1-cos(x[1]))^2/sin(x[1])^3)-p[2]\*sin(x[1])-p[3]\*x[2]-p[4]\*x[2]^3+(p[2]+p[6]\*sin(p[5]\*t)) _sin(x[1])  
du[3]=dz[1]=z[2]  
du[4]=dz[2]=-p[1]^2_ ((1-cos(z[1]))^2/sin(z[1])^3)-p[2]\*sin(z[1])-p[3]\*z[2]-p[4] _z[2]^3+(p[2]+p[6] sin(p[5] t)) sin(z[1])+0.000001 sin(x[1])+0.4 sin(pi t)  
du[5]=de[1]=x[2]-z[2]  
du[6]=de[2]=-p[1]^2_ ((1-cos(x[1]))^2/sin(x[1])^3)-p[2]\*sin(x[1])-p[3]\*x[2]-p[4]\*x[2]^3+(p[2]+p[6]\*sin(p[5]\*t)) _sin(x[1])-(-p[1]^2_ ((1-cos(z[1]))^2/sin(z[1])^3)-p[2]\*sin(z[1])-p[3]\*z[2]-p[4]\*z[2]^3+(p[2]+p[6] _sin(p[5] t)) sin(z[1])+0.000001 sin(x[1])+0.4 sin(pi_ t))  
end  
u0 = [1;-1;1.6;0.8;0;-1.8]  
tspan = (0.0,10.0)  
p = [1.5,1.0,3.0,1.0]  
prob = ODEProblem(myfun,u0,tspan,p)  
sol=solve(prob)

ERROR: BoundsError  
Stacktrace:  
[1] getindex  
@ .\number.jl:96 [inlined]  
[2] myfun(du::Vector{Float64}, u::Vector{Float64}, p::Vector{Float64}, t::Float64)  
@ Main .\REPL[4]:3  
[3] ODEFunction  
@ C:\Users\user.julia\packages\SciMLBase\oTP8b\src\scimlfunctions.jl:334 [inlined]  
[4] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, true, Vector{Float64}, Nothing, Float64, Vector{Float64}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, OrdinaryDiffEq.ODECompositeSolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.CompositeInterpolationData{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE\_DEFAULT\_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Float64}, Nothing, Nothing, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, cache::OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\perform\_step\low\_order\_rk\_perform\_step.jl:623  
[5] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, true, Vector{Float64}, Nothing, Float64, Vector{Float64}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, OrdinaryDiffEq.ODECompositeSolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.CompositeInterpolationData{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE\_DEFAULT\_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Float64}, Nothing, Nothing, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, cache::OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\perform\_step\composite\_perform\_step.jl:39  
[6] \_\_init(prob::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, AutoSwitch{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, timeseries\_init::Tuple{}, ts\_init::Tuple{}, ks\_init::Tuple{}, recompile::Type{Val{true}}; saveat::Tuple{}, tstops::Tuple{}, d\_discontinuities::Tuple{}, save\_idxs::Nothing, save\_everystep::Bool, save\_on::Bool, save\_start::Bool, save\_end::Nothing, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force\_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Nothing, reltol::Nothing, qmin::Rational{Int64}, qmax::Int64, qsteady\_min::Int64, qsteady\_max::Int64, beta1::Nothing, beta2::Nothing, qoldinit::Rational{Int64}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE\_DEFAULT\_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), unstable\_check::typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), verbose::Bool, timeseries\_errors::Bool, dense\_errors::Bool, advance\_to\_tstop::Bool, stop\_at\_next\_tstop::Bool, initialize\_save::Bool, progress::Bool, progress\_steps::Int64, progress\_name::String, progress\_message::typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), userdata::Nothing, allow\_extrapolation::Bool, initialize\_integrator::Bool, alias\_u0::Bool, alias\_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:default\_set, :second\_time), Tuple{Bool, Bool}}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\solve.jl:456  
[7] \_\_solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, AutoSwitch{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}; kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:default\_set, :second\_time), Tuple{Bool, Bool}}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\solve.jl:4  
[8] \_\_solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::Nothing; default\_set::Bool, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:second\_time,), Tuple{Bool}}})  
@ DifferentialEquations C:\Users\user.julia\packages\DifferentialEquations\ddA0E\src\default\_solve.jl:7  
[9] #\_\_solve#73  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:282 [inlined]  
[10] \_\_solve  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:269 [inlined]  
[11] #solve\_call#58  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:61 [inlined]  
[12] solve\_call  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:48 [inlined]  
[13] #solve\_up#60  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:85 [inlined]  
[14] solve\_up  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:75 [inlined]  
[15] #solve#59  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:70 [inlined]  
[16] solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem})  
@ DiffEqBase C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:68  
[17] top-level scope  
@ REPL[9]:1

I do not know if I have acted in a right way

and How must I solve this and then pick up “e”.(extract e as a part of the solution)

Thanks in advances.

---

<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:** [July 19, 2021, 10:32am UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/2 "2021-07-19T10:32:17Z")

</div>

> [@aiiiob\_bie](#):
>
> dx[1]

That variable doesn’t exist. Why not just write `du[1] = x[2]`?

---

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 19, 2021, 11:13am UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/3 "2021-07-19T11:13:04Z")

</div>

Thank so much for your reply.

I wanted to assume u as an array of x ,z,e  
In fact my problem is solving 6 odes but in the function command  
I faced to a limitation which is

in “my fun” function I could just one function namely as u

so I decided to for u as a vector that its first  
derivative is derivative of x[1] and the second is derivative of x[2] and the third component is  
the first derivative of the next vector z and …I continued in this way

and yes when I gain look at it it seems not true

How must it be defined?

After removing dx[1],…I got the same error

using DifferentialEquations

julia\> function myfun(du,u,p,t)  
x, z, e = u  
du[1] = x[2]  
du[2] = -p[1]^2\*((1-cos(x[1]))^2/sin(x[1])^3)-p[2]\*sin(x[1])-p[3]\*x[2]-p[4]\*x[2]^3+(p[2]+p[6]\*sin(p[5]\*t))_sin(x[1])  
du[3]=z[2]  
du[4]=-p[1]^2_((1-cos(z[1]))^2/sin(z[1])^3)-p[2]\*sin(z[1])-p[3]\*z[2]-p[4]_z[2]^3+(p[2]+p[6]sin(p[5]t))sin(z[1])+0.000001sin(x[1])+0.4sin(pit)  
du[5]=x[2]-z[2]  
du[6]-p[1]^2_((1-cos(x[1]))^2/sin(x[1])^3)-p[2]\*sin(x[1])-p[3]\*x[2]-p[4]\*x[2]^3+(p[2]+p[6]\*sin(p[5]\*t))_sin(x[1])-(-p[1]^2_((1-cos(z[1]))^2/sin(z[1])^3)-p[2]\*sin(z[1])-p[3]\*z[2]-p[4]\*z[2]^3+(p[2]+p[6]_sin(p[5]t))sin(z[1])+0.000001sin(x[1])+0.4sin(pi_t))  
end  
myfun (generic function with 1 method)

julia\> u0 = [1;-1;1.6;0.8;0;-1.8]  
6-element Vector{Float64}:  
1.0  
-1.0  
1.6  
0.8  
0.0  
-1.8

julia\> tspan = (0.0,10.0)  
(0.0, 10.0)

julia\> p = [1.5,1.0,3.0,1.0]  
4-element Vector{Float64}:  
1.5  
1.0  
3.0  
1.0

julia\> prob = ODEProblem(myfun,u0,tspan,p)  
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true  
timespan: (0.0, 10.0)  
u0: 6-element Vector{Float64}:  
1.0  
-1.0  
1.6  
0.8  
0.0  
-1.8

julia\> sol=solve(prob)  
ERROR: BoundsError  
Stacktrace:  
[1] getindex  
@ .\number.jl:96 [inlined]  
[2] myfun(du::Vector{Float64}, u::Vector{Float64}, p::Vector{Float64}, t::Float64)  
@ Main .\REPL[4]:3  
[3] ODEFunction  
@ C:\Users\user.julia\packages\SciMLBase\oTP8b\src\scimlfunctions.jl:334 [inlined]  
[4] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, true, Vector{Float64}, Nothing, Float64, Vector{Float64}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, OrdinaryDiffEq.ODECompositeSolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.CompositeInterpolationData{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE\_DEFAULT\_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Float64}, Nothing, Nothing, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, cache::OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\perform\_step\low\_order\_rk\_perform\_step.jl:623  
[5] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, true, Vector{Float64}, Nothing, Float64, Vector{Float64}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, OrdinaryDiffEq.ODECompositeSolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.CompositeInterpolationData{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE\_DEFAULT\_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Float64}, Nothing, Nothing, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, cache::OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\perform\_step\composite\_perform\_step.jl:39  
[6] \_\_init(prob::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, AutoSwitch{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, timeseries\_init::Tuple{}, ts\_init::Tuple{}, ks\_init::Tuple{}, recompile::Type{Val{true}}; saveat::Tuple{}, tstops::Tuple{}, d\_discontinuities::Tuple{}, save\_idxs::Nothing, save\_everystep::Bool, save\_on::Bool, save\_start::Bool, save\_end::Nothing, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force\_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Nothing, reltol::Nothing, qmin::Rational{Int64}, qmax::Int64, qsteady\_min::Int64, qsteady\_max::Int64, beta1::Nothing, beta2::Nothing, qoldinit::Rational{Int64}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE\_DEFAULT\_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), unstable\_check::typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), verbose::Bool, timeseries\_errors::Bool, dense\_errors::Bool, advance\_to\_tstop::Bool, stop\_at\_next\_tstop::Bool, initialize\_save::Bool, progress::Bool, progress\_steps::Int64, progress\_name::String, progress\_message::typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), userdata::Nothing, allow\_extrapolation::Bool, initialize\_integrator::Bool, alias\_u0::Bool, alias\_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:default\_set, :second\_time), Tuple{Bool, Bool}}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\solve.jl:456  
[7] \_\_solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, AutoSwitch{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}; kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:default\_set, :second\_time), Tuple{Bool, Bool}}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\solve.jl:4  
[8] \_\_solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::Nothing; default\_set::Bool, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:second\_time,), Tuple{Bool}}})  
@ DifferentialEquations C:\Users\user.julia\packages\DifferentialEquations\ddA0E\src\default\_solve.jl:7  
[9] #\_\_solve#73  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:282 [inlined]  
[10] \_\_solve  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:269 [inlined]  
[11] #solve\_call#58  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:61 [inlined]  
[12] solve\_call  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:48 [inlined]  
[13] #solve\_up#60  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:85 [inlined]  
[14] solve\_up  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:75 [inlined]  
[15] #solve#59  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:70 [inlined]  
[16] solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem})  
@ DiffEqBase C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:68  
[17] top-level scope  
@ REPL[9]:1

---

<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:** [July 19, 2021, 11:17am UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/4 "2021-07-19T11:17:07Z")

</div>

> [@aiiiob\_bie](#):
>
> x, z, e = u

Those are all scalars, so `z[2]` doesn’t make sense. Did you mean:

```julia
x = @view u[1:2]
u = @view u[3:4]
e = @view u[5,6]

```

You might want to look at this package as a nice abstraction:

> **[GitHub - jonniedie/ComponentArrays.jl: Arrays with arbitrarily nested named...](https://github.com/jonniedie/ComponentArrays.jl)**
>
> Arrays with arbitrarily nested named components. Contribute to jonniedie/ComponentArrays.jl development by creating an account on GitHub.

---

<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:** [July 19, 2021, 12:05pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/6 "2021-07-19T12:05:00Z")

</div>

Yes, what I mentioned above should work. Did you try it? Or did you try ComponentArrays.jl as an abstraction?

---

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 19, 2021, 12:19pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/7 "2021-07-19T12:19:20Z")

</div>

unfortunately I could not install ComponentArrays

julia\> import Pkg

julia\> Pkg.add(“ComponentArray”)  
Updating registry at `C:\Users\user\.julia\registries\General`  
Updating registry at `C:\Users\user\.julia\registries\JuliaComputingRegistry`  
ERROR: The following package names could not be resolved:

- ComponentArray (not found in project, manifest or registry)

Stacktrace:  
[1] pkgerror(msg::String)  
@ Pkg.Types C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\Types.jl:55  
[2] ensure\_resolved(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; registry::Bool)  
@ Pkg.Types C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\Types.jl:866  
[3] add(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; preserve::Pkg.Types.PreserveLevel, platform::Base.BinaryPlatforms.Platform, kwargs::Base.Iterators.Pairs{Symbol, Base.TTY, Tuple{Symbol}, NamedTuple{(:io,), Tuple{Base.TTY}}})  
@ Pkg.API C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:192  
[4] add(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})  
@ Pkg.API C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:79  
[5] add(pkgs::Vector{Pkg.Types.PackageSpec})  
@ Pkg.API C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:77  
[6] #add#23  
@ C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:75 [inlined]  
[7] add  
@ C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:75 [inlined]  
[8] #add#22  
@ C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:74 [inlined]  
[9] add(pkg::String)  
@ Pkg.API C:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\API.jl:74  
[10] top-level scope  
@ REPL[2]:1

---

<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:** [July 19, 2021, 12:59pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/8 "2021-07-19T12:59:27Z")

</div>

> [@aiiiob\_bie](#):
>
> Pkg.add(“ComponentArray”)

Pkg.add(“ComponentArrays”)

---

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 19, 2021, 1:00pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/9 "2021-07-19T13:00:03Z")

</div>

Are there examples applying this type of indexing?  
Must ComponentArrays.jl be installed for it?  
(x = @view u[1:2]  
u = @view u[3:4]  
e = @view u[5,6])

---

<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:** [July 19, 2021, 1:04pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/10 "2021-07-19T13:04:08Z")

</div>

Look at the doumentation.

---

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 19, 2021, 1:04pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/11 "2021-07-19T13:04:39Z")

</div>

Thank you so much sorry for my primitive questions.

---

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 19, 2021, 2:09pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/12 "2021-07-19T14:09:15Z")

</div>

Dear Chris

I read the section for ODE in

> **[GitHub - jonniedie/ComponentArrays.jl: Arrays with arbitrarily nested named...](https://github.com/jonniedie/ComponentArrays.jl)**
>
> Arrays with arbitrarily nested named components. Contribute to jonniedie/ComponentArrays.jl development by creating an account on GitHub.

Unfortunately, I couldn’t find any clue How can I relate this these two with each other

Is there an example that can guid me?

I know that this will introduce an interesting indexing which will probably solve the problem  
x = @view u[1:2]  
u = @view u[3:4]  
e = @view u[5,6]  
but I could not find an example that applies this to solve an ODE.

I also rewrite the previous code in this format  
using DifferentialEquations  
using LinearAlgebra  
using Plots  
#u=[x[1],x[2],z[1],z[2],e[1],e[2]]  
function f(t, u)  
return [u[2], -p[1]^2\*((1-cos(u[1]))^2/sin(u[1])^3)-p[2]\*sin(u[1])-p[3]\*u[2]-p[4]\*u[2]^3+(p[2]+p[6]\*sin(p[5]\*t))_sin(u[1]), u[4], -p[1]^2_((1-cos(u[3]))^2/sin(u[3])^3)-p[2]\*sin(u[3])-p[3]\*u[4]-p[4]_u[4]^3+(p[2]+p[6]sin(p[5]t))sin(u[3])+0.000001sin(u[3])+0.4sin(pit),u[6],-p[1]^2_((1-cos(u[1]))^2/sin(u[1])^3)-p[2]\*sin(u[1])-p[3]\*u[2]-p[4]\*u[2]^3+(p[2]+p[6]\*sin(p[5]\*t))_sin(u[1])-( -p[1]^2_((1-cos(u[3]))^2/sin(u[3])^3)-p[2]\*sin(u[3])-p[3]\*u[4]-p[4]\*u[4]^3+(p[2]+p[6]_sin(p[5]t))sin(u[3])+0.000001sin(u[3])+0.4sin(pi_t))]  
end  
u0 = [1;-1;1.6;0.8;0;-1.8]  
tspan = (0.0,10.0)  
p = [1.5,1.0,3.0,1.0]  
prob = ODEProblem(myfun,u0,tspan,p)  
sol=solve(prob)

but unfortunately, it didn’t work again

julia\> sol=solve(prob)  
ERROR: BoundsError: attempt to access 6-element Vector{Float64} at index [5, 6]  
Stacktrace:  
[1] throw\_boundserror(A::Vector{Float64}, I::Tuple{Int64, Int64})  
@ Base .\abstractarray.jl:651  
[2] checkbounds  
@ .\abstractarray.jl:616 [inlined]  
[3] view  
@ .\subarray.jl:177 [inlined]  
[4] myfun(du::Vector{Float64}, u::Vector{Float64}, p::Vector{Float64}, t::Float64)  
@ Main .\REPL[5]:4  
[5] ODEFunction  
@ C:\Users\user.julia\packages\SciMLBase\oTP8b\src\scimlfunctions.jl:334 [inlined]  
[6] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, true, Vector{Float64}, Nothing, Float64, Vector{Float64}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, OrdinaryDiffEq.ODECompositeSolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.CompositeInterpolationData{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE\_DEFAULT\_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Float64}, Nothing, Nothing, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, cache::OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\perform\_step\low\_order\_rk\_perform\_step.jl:623  
[7] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, true, Vector{Float64}, Nothing, Float64, Vector{Float64}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, OrdinaryDiffEq.ODECompositeSolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.CompositeInterpolationData{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE\_DEFAULT\_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Float64}, Nothing, Nothing, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, cache::OrdinaryDiffEq.CompositeCache{Tuple{OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.Rosenbrock23Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEq.Rosenbrock23Tableau{Float64}, SciMLBase.TimeGradientWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}}, SciMLBase.UJacobianWrapper{ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Float64, Vector{Float64}}, DefaultLinSolve, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, FiniteDiff.GradientCache{Nothing, Vector{Float64}, Vector{Float64}, Float64, Val{:forward}(), Float64, Val{true}()}}}, OrdinaryDiffEq.AutoSwitchCache{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\perform\_step\composite\_perform\_step.jl:39  
[8] \_\_init(prob::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, AutoSwitch{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}, timeseries\_init::Tuple{}, ts\_init::Tuple{}, ks\_init::Tuple{}, recompile::Type{Val{true}}; saveat::Tuple{}, tstops::Tuple{}, d\_discontinuities::Tuple{}, save\_idxs::Nothing, save\_everystep::Bool, save\_on::Bool, save\_start::Bool, save\_end::Nothing, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force\_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Nothing, reltol::Nothing, qmin::Rational{Int64}, qmax::Int64, qsteady\_min::Int64, qsteady\_max::Int64, beta1::Nothing, beta2::Nothing, qoldinit::Rational{Int64}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE\_DEFAULT\_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE\_DEFAULT\_ISOUTOFDOMAIN), unstable\_check::typeof(DiffEqBase.ODE\_DEFAULT\_UNSTABLE\_CHECK), verbose::Bool, timeseries\_errors::Bool, dense\_errors::Bool, advance\_to\_tstop::Bool, stop\_at\_next\_tstop::Bool, initialize\_save::Bool, progress::Bool, progress\_steps::Int64, progress\_name::String, progress\_message::typeof(DiffEqBase.ODE\_DEFAULT\_PROG\_MESSAGE), userdata::Nothing, allow\_extrapolation::Bool, initialize\_integrator::Bool, alias\_u0::Bool, alias\_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:default\_set, :second\_time), Tuple{Bool, Bool}}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\solve.jl:456  
[9] \_\_solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::CompositeAlgorithm{Tuple{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}}, AutoSwitch{Tsit5, Rosenbrock23{0, false, DefaultLinSolve, DataType}, Rational{Int64}, Int64}}; kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:default\_set, :second\_time), Tuple{Bool, Bool}}})  
@ OrdinaryDiffEq C:\Users\user.julia\packages\OrdinaryDiffEq\a5qvy\src\solve.jl:4  
[10] \_\_solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, ::Nothing; default\_set::Bool, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:second\_time,), Tuple{Bool}}})  
@ DifferentialEquations C:\Users\user.julia\packages\DifferentialEquations\ddA0E\src\default\_solve.jl:7  
[11] #\_\_solve#73  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:282 [inlined]  
[12] \_\_solve  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:269 [inlined]  
[13] #solve\_call#58  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:61 [inlined]  
[14] solve\_call  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:48 [inlined]  
[15] #solve\_up#60  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:85 [inlined]  
[16] solve\_up  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:75 [inlined]  
[17] #solve#59  
@ C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:70 [inlined]  
[18] solve(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, ODEFunction{true, typeof(myfun), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT\_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem})  
@ DiffEqBase C:\Users\user.julia\packages\DiffEqBase\oe7VF\src\solve.jl:68  
[19] top-level scope  
@ REPL[22]:1

---

<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:** [July 19, 2021, 2:23pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/13 "2021-07-19T14:23:05Z")

</div>

> [@aiiiob\_bie](#):
>
> function f(t, u)

That’s not even one of the allowed function signatures. Look at [GitHub - jonniedie/ComponentArrays.jl: Arrays with arbitrarily nested named components.](https://github.com/jonniedie/ComponentArrays.jl#differential-equation-example), copy paste it, and then modify it towards your model.

---

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 20, 2021, 1:49pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/14 "2021-07-20T13:49:13Z")

</div>

Dear Chris  
Here is a code I executed  
using ComponentArrays  
using DifferentialEquations  
using Parameters: @unpack

# System 1

@parameters t σ ρ β f(t)  
@variables x(t) y(t) z(t)  
@derivatives D’~t  
eqs = [D(x) ~ σ\*(y-x),  
D(y) ~ x\*(ρ-z)-y + f(t),  
D(z) ~ x_y - β_z]  
lorenz = ODESystem(eqs)

# System 2

@parameters t α β γ δ f(t)  
@variables x(t) y(t)  
@derivatives D’~t  
eqs = [D(x) ~ α_x - β_x_y + f(t)  
D(y) ~ -γ_y + δ_x_y]  
lotka = ODESystem(eqs)

# Composed System

eqs = [lorenz.eqs;lotka.eqs;lorenz.f ~ lotka.x;lotka.f ~ lorenz.y]

#### Should be

[  
D(lorenz\_x) ~ lorenz\_σ\*(lorenz\_y-lorenz\_x),  
D(lorenz\_y) ~ lorenz\_x\*(lorenz\_ρ-lorenz\_z)-lorenz\_y + lotka\_y,  
D(lorenz\_z) ~ lorenz\_x_lorenz\_y - lorenz\_β_lorenz\_z,  
D(lotka\_x) ~ lotka\_α_lotka\_x - lotka\_β_lotka\_x_lotka\_y + lorenz\_x,  
D(lotka\_y) ~ -lotka\_γ_lotka\_y + lotka\_δ_lotka\_x_lotka\_y  
]

I got

ERROR: Sym f(t) is not callable. Use @syms f(t)(var1, var2,…) to create it as a callable.  
Stacktrace:  
[1] error(s::String)  
@ Base .\error.jl:33  
[2] (::Term{Real, Base.ImmutableDict{DataType, Any}})(args::Sym{Real, Base.ImmutableDict{DataType, Any}})  
@ SymbolicUtils C:\Users\user.julia\packages\SymbolicUtils\SXYR9\src\types.jl:202  
[3] (::Num)(args::Num)  
@ Symbolics C:\Users\user.julia\packages\Symbolics\CRJbI\src\num.jl:21  
[4] top-level scope  
@ REPL[8]:1

julia\> lorenz = ODESystem(eqs)  
ERROR: UndefVarError: eqs not defined  
Stacktrace:  
[1] top-level scope  
@ REPL[9]:1

julia\> # System 2

julia\> @parameters t α β γ δ f(t)  
6-element Vector{Num}:  
t  
α  
β  
γ  
δ  
f(t)

julia\> @variables x(t) y(t)  
2-element Vector{Num}:  
x(t)  
y(t)

julia\> @derivatives D’~t  
(Differential(t),)

julia\> eqs = [D(x) ~ α_x - β_x_y + f(t)  
D(y) ~ -γ_y + δ_x_y]  
ERROR: Sym f(t) is not callable. Use @syms f(t)(var1, var2,…) to create it as a callable.  
Stacktrace:  
[1] error(s::String)  
@ Base .\error.jl:33  
[2] (::Term{Real, Base.ImmutableDict{DataType, Any}})(args::Sym{Real, Base.ImmutableDict{DataType, Any}})  
@ SymbolicUtils C:\Users\user.julia\packages\SymbolicUtils\SXYR9\src\types.jl:202  
[3] (::Num)(args::Num)  
@ Symbolics C:\Users\user.julia\packages\Symbolics\CRJbI\src\num.jl:21  
[4] top-level scope  
@ REPL[14]:1

julia\> lotka = ODESystem(eqs)  
ERROR: UndefVarError: eqs not defined  
Stacktrace:  
[1] top-level scope  
@ REPL[15]:1

julia\> # Composed System

julia\> eqs = [lorenz.eqs;lotka.eqs;lorenz.f ~ lotka.x;lotka.f ~ lorenz.y]  
ERROR: UndefVarError: lorenz not defined  
Stacktrace:  
[1] top-level scope  
@ REPL[17]:1

julia\>

julia\> #### Should be

julia\> [  
D(lorenz\_x) ~ lorenz\_σ\*(lorenz\_y-lorenz\_x),  
D(lorenz\_y) ~ lorenz\_x\*(lorenz\_ρ-lorenz\_z)-lorenz\_y + lotka\_y,  
D(lorenz\_z) ~ lorenz\_x_lorenz\_y - lorenz\_β_lorenz\_z,  
D(lotka\_x) ~ lotka\_α_lotka\_x - lotka\_β_lotka\_x_lotka\_y + lorenz\_x,  
D(lotka\_y) ~ -lotka\_γ_lotka\_y + lotka\_δ_lotka\_x_lotka\_y  
]  
ERROR: UndefVarError: lorenz\_x not defined  
Stacktrace:  
[1] top-level scope  
@ REPL[19]:1

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [July 20, 2021, 3:35pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/15 "2021-07-20T15:35:01Z")

</div>

A couple of suggestions…

1. Use the standard way of annotating computer code via the _backtick_ symbol (\text{`}):  
a. For inline code elements, use backtick in front of the code and after the code, e.g., `x,y,e = u`.  
b. For computer code over several lines, put the code block after a line with triple backtics followed by word `julia` (i.e., \text{```julia}), and insert a line with triple backticks _after_ the code block (\text{```}).  
This will make your code much easier to read.
2. Understand unpacking of collections + the use of `view`.

In your code, your vector `u` has 6 elements, and you write `x,z,e = u`. You intend each of `x`, `z`, and `e` to be vectors with 2 elements.

- Question: how do you think Julia can figure out that you want each of `x`, `z`, and `e` to have 2 elements? What if Julia thinks `x` has one element, `z` has one element, and `e` has 4 elements? Or something else?

In fact, Julia assumes that `x`, `z`, and `e` have one element each, and then just forgets about the remaining 3 elements, as in the following example:

```julia
julia> u = collect(1:6);
julia> x,z,e = u;
julia> x
1
julia> z
2
julia> e
3

```

This means that when you refer to, say, `x[2]`, Julia has to throw an error message: `x[2]` doesn’t exist!

Instead, you can define `x`, `z`, and `e` as _views_ into vector `u`, as Chris suggests. You can define `x` as a view into the first two elements of `u` in two ways: both

```julia
x = view(u,1:2)

```

and

```julia
x = @view u[1:2]

```

will work. The second form is what Chris suggests. Check out keyword `view` in Julia’s on-line documentation!

```julia
julia> x = view(u,1:2)
2-element view(::Vector{Int64}, 1:2) with eltype Int64:
 1
 2
julia> x[2]
2
julia> x[2] = -2
-2
julia> x
2-element view(::Vector{Int64}, 1:2) with eltype Int64:
  1
 -2
julia> u
6-element Vector{Int64}:
  1
 -2
  3
  4
  5
  6

```

I tried to run my modification of your _first_ code:

```julia
using DifferentialEquations, Plots
function myfun(du,u,p,t)
	x = @view u[1:2]
	z = @view u[3:4]
	e = @view u[5:6]
	du[1] = x[2]
	du[2] = -p[1]^2*((1-cos(x[1]))^2/sin(x[1])^3)-p[2]*sin(x[1])-p[3]*x[2]-p[4]*x[2]^3+(p[2]+p[6]*sin(p[5]*t))sin(x[1])
	du[3]=z[2]
	du[4]=-p[1]^2((1-cos(z[1]))^2/sin(z[1])^3)-p[2]*sin(z[1])-p[3]*z[2]-p[4]z[2]^3+(p[2]+p[6]sin(p[5]t))sin(z[1])+0.000001sin(x[1])+0.4sin(pit)
	du[5]=x[2]-z[2]
	du[6]-p[1]^2((1-cos(x[1]))^2/sin(x[1])^3)-p[2]*sin(x[1])-p[3]*x[2]-p[4]*x[2]^3+(p[2]+p[6]*sin(p[5]*t))sin(x[1])-(-p[1]^2((1-cos(z[1]))^2/sin(z[1])^3)-p[2]*sin(z[1])-p[3]*z[2]-p[4]*z[2]^3+(p[2]+p[6]sin(p[5]t))sin(z[1])+0.000001sin(x[1])+0.4sin(pit))
end

u0 = [1,-1,1.6,0.8,0,-1.8]
tspan = (0.0,10.0)
p = [1.5,1.0,3.0,1.0]
prob = ODEProblem(myfun,u0,tspan,p)
sol=solve(prob)

```

The code _still_ crashes. The reason is that in your `myfun` function, you refer to `p[5]` and `p[6]`, but your `p` vector only contains 4 elements…

If I fix this by changing `p` to, e.g.,

```julia
p = [1.5,1.0,3.0,1.0,0.1,0.1]

```

your code _once more_ crashes. The reason is that your `myfun` function contains the variable `pit` in two locations. If I _assume_ that `pit` really is a typo for `pi*t`, _then_ the code runs and produces a result.

In other words, the code:

```julia
using DifferentialEquations, Plots
function myfun(du,u,p,t)
	x = @view u[1:2]
	z = @view u[3:4]
	e = @view u[5:6]
	du[1] = x[2]
	du[2] = -p[1]^2*((1-cos(x[1]))^2/sin(x[1])^3)-p[2]*sin(x[1])-p[3]*x[2]-p[4]*x[2]^3+(p[2]+p[6]*sin(p[5]*t))sin(x[1])
	du[3]=z[2]
	du[4]=-p[1]^2((1-cos(z[1]))^2/sin(z[1])^3)-p[2]*sin(z[1])-p[3]*z[2]-p[4]z[2]^3+(p[2]+p[6]sin(p[5]t))sin(z[1])+0.000001sin(x[1])+0.4sin(pi*t)
	du[5]=x[2]-z[2]
	du[6]-p[1]^2((1-cos(x[1]))^2/sin(x[1])^3)-p[2]*sin(x[1])-p[3]*x[2]-p[4]*x[2]^3+(p[2]+p[6]*sin(p[5]*t))sin(x[1])-(-p[1]^2((1-cos(z[1]))^2/sin(z[1])^3)-p[2]*sin(z[1])-p[3]*z[2]-p[4]*z[2]^3+(p[2]+p[6]sin(p[5]t))sin(z[1])+0.000001sin(x[1])+0.4sin(pi*t))
end

u0 = [1,-1,1.6,0.8,0,-1.8]
tspan = (0.0,10.0)
p = [1.5,1.0,3.0,1.0,0.1,0.1] # I have extended your p vector with two elements of 0.1 since your code refers to p[5] and p[6]
prob = ODEProblem(myfun,u0,tspan,p)
sol=solve(prob)

```

works.

Of course, I have chosen artificial values for `p[5:6]`, so the solution found by the above code block will most likely not make much sense.

---

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 20, 2021, 6:37pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/16 "2021-07-20T18:37:30Z")

</div>

Dear Bernt

Thank you so much for guiding me.

If I want to extract and store all u[5] and u[6] solutions into a separate vector for instance “e”  
( e =[u[5];u[6]])

Then must I write

e=sol[[:5];sol[:6]]

Again I am so thankful.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [July 20, 2021, 9:04pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/17 "2021-07-20T21:04:31Z")

</div>

[Please learn to use backticks around computer code…]

The solution `sol` can be viewed in two ways:

1. As solution for the 6 states (`u`) in time points given by vector `sol.t`. To pick out the values of the states in the temporal points, do `Sol = Array(sol)`. The time series for element `j` of `u` is then found in row `j` of `Sol`. It is then trivial to plot the result:

```julia
tm = sol.t # vector of points in time for solution
Sol = Array(sol) # matrix of time series for u
# e1
plot(tm,Sol[5,:])
# e2
plot!(tm,Sol[6,:])

```

leads to

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/9/39c758f3d5c7f8e2af53133a67686eac3d78cbdb.png)

1. However, the `DifferentialEquations` package is smarter than this! The solution `sol` doesn’t only contain the data points – in addition, `sol` contains interpolation functions for the solution. So if you instead use the interpolation functions, you get a smoother plot!

You can compute the solution (`u`) for an arbitrary point in time, e.g., `t = pi`:

```julia
julia> sol(pi)
6-element Vector{Float64}:
  0.36914613714087563
 -0.07479655486691363
  0.45527184851504104
 -0.3309227866720121
  0.5138742886258347
 -1.8

```

[I use “prompt” `julia\>` when I also want to show the output/response from the command…]

In addition, the `DifferentialEquations` package contains so-called “recipes” for simplifying plotting of the solution. So you can plot `e1` and `e2` as follows, where you take advantage of the interpolation functions:

```julia
plot(sol,vars=(0,5))
plot!(sol,vars=(0,6))

```

[`vars=(0,5)` means plot the solution where you use the zeroth element = time as abscissa, and the fifth element = `e1` as ordinate] leading to:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/4/3424c515e487054b2c8f1b9e953a1803cd3e0e68.png)

So… if you want to plot, say, `z2` as a function of `x1`…

```julia
plot(sol,vars=(1,4))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/8/d87c9733200189be0adab5349a73d648e7e69c48.png)

Finally, suppose that you don’t really care about `x` and `z` in your plots – then, don’t store them when you solve the problem:

```julia
sol=solve(prob,save_idxs=[5,6])
plot(sol)

```

leading to

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/b/bb4023eaca268eeda89c9723e8669f75c857ce72.png)

Finally, finally: you want to save the solutions?

- It is straightforward to save matrix `Sol`, or some of the rows of `Sol` – this `Array` is a built-in data structure of Julia.
- You can also save the solution itself (`sol`), which includes the interpolation function. But then you need to save the result in a more complex data file.

Good luck.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [July 20, 2021, 9:28pm UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/18 "2021-07-20T21:28:45Z")

</div>

@aiiiob_bie This link shows you how to use backticks to format your code snippets nicely and other helpful things: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![aiiiob\_bie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiiiob_bie/32/27296_2.png) [@aiiiob\_bie](https://discourse.julialang.org/u/aiiiob_bie)\
**Post date:** [July 21, 2021, 3:53am UTC](https://discourse.julialang.org/t/ode-with-vector-argument/64918/19 "2021-07-21T03:53:50Z")

</div>

Dear Bernt , Chris and John

I really appreciate you.
