ODE with vector Argument

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.

That variable doesnā€™t exist. Why not just write du[1] = x[2]?

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(pit))
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

Those are all scalars, so z[2] doesnā€™t make sense. Did you mean:

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:

1 Like

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

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

Pkg.add(ā€œComponentArraysā€)

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])

Look at the doumentation.

Thank you so much sorry for my primitive questions.

Dear Chris

I read the section for ODE in

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(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)

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

Thatā€™s not even one of the allowed function signatures. Look at GitHub - jonniedie/ComponentArrays.jl: Arrays with arbitrarily nested named components., copy paste it, and then modify it towards your model.

1 Like

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) ~ xy - Ī²z]
lorenz = ODESystem(eqs)

System 2

@parameters t Ī± Ī² Ī³ Ī“ f(t)
@variables x(t) y(t)
@derivatives Dā€™~t
eqs = [D(x) ~ Ī±x - Ī²xy + f(t)
D(y) ~ -Ī³
y + Ī“xy]
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_xlorenz_y - lorenz_Ī²lorenz_z,
D(lotka_x) ~ lotka_Ī±lotka_x - lotka_Ī²lotka_xlotka_y + lorenz_x,
D(lotka_y) ~ -lotka_Ī³
lotka_y + lotka_Ī“lotka_xlotka_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 - Ī²xy + f(t)
D(y) ~ -Ī³
y + Ī“xy]
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_xlorenz_y - lorenz_Ī²lorenz_z,
D(lotka_x) ~ lotka_Ī±lotka_x - lotka_Ī²lotka_xlotka_y + lorenz_x,
D(lotka_y) ~ -lotka_Ī³
lotka_y + lotka_Ī“lotka_xlotka_y
]
ERROR: UndefVarError: lorenz_x not defined
Stacktrace:
[1] top-level scope
@ REPL[19]:1

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> 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

x = view(u,1:2)

and

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> 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:

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.,

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:

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.

1 Like

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.

[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:
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

  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> 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:

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:

Soā€¦ if you want to plot, say, z2 as a function of x1ā€¦

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

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:

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

leading to

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.

1 Like

@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

2 Likes

Dear Bernt , Chris and John

I really appreciate you.

1 Like