Hello, I am new to Julia. I have used MATLAB earlier. I am trying to solve a system of ODE using BoundaryValueDiffEq with the help of simple pendulum example in Julia docs and I am getting an error. Please help me resolve it.
using NeuralPDE, Flux, ModelingToolkit, GalacticOptim, Optim, DiffEqFlux, OrdinaryDiffEq,BoundaryValueDiffEq, Plots
import ModelingToolkit: Interval, infimum, supremum
@parameters eta
@variables y1(..),y2(..),y3(..),y4(..),y5(..),y6(..),y7(..),y8(..)
Deta = Differential(eta)
eta_min= 0.
eta_max = 6.0
lambda=-1
n=0.5
S=2.2
beta=1.1
K1=0.1
rad=2
phi0=0.005
Pr=21
Rhof=1150
Rhos=19300
Cpf=3617
Cps=128
Kf=0.53
Ks=328
tmp1=1-phi0
tmp2=Ks-Kf
tmp3=Ks+2*Kf
tmp4=Cps*Rhos
tmp5=Cpf*Rhof
A1=tmp1+phi0*Rhos/Rhof
A2=tmp1^(-2.5)
A3=(2*phi0*tmp2+tmp3)/(-1*phi0*tmp2+tmp3)
A4=tmp1+phi0*tmp4/tmp5
eb = eta + beta
tspan = (0.0,6.0)
function simplependulum!(dz,z,p,eta)
form1=A2+K1
form2=z[2]*z[3]-z[1]*z[4]
form3=z[2]*z[1]-z[1]*z[3]
form4=z[1]*z[6]-z[5]*z[2]
form5=-2*z[4]/eb
form6=z[3]/(eb^2)
form7=z[3]/(eb^3)
form8=beta*A1/eb
form9=beta*A1/eb^2
form10=beta*A1/eb^3
form11=K1*z[6]/eb
form12=-1*z[6]/eb
form13=K1/A1
form14=z[2]/eb
form15=-1*z[8]/eb
vari1=beta/(eb*(A2/A1+2*form13))
vari2=2*z[5]+z[3]+form14
vari3=A4*Pr*beta/((A3+4/3*rad)*eb)
formu3=form15-vari3*z[8]*z[1]
formu2=form12-vari1*form4+form13*vari2
formu1=(form1*(form5+form6-form7)+form8*form2+form9*form3+form10*z[2]*z[1]+form11+K1*formu2)/form1
dz[1] = z[2]
dz[2] = z[3]
dz[3] = z[4]
dz[4] = formu1
dz[5] = z[6]
dz[6] = formu2
dz[7] = z[8]
dz[8] = formu3
end
function bc1!(residual, z, p, eta)
residual[1] = z[1][1] - S
residual[2] = z[1][2] - lambda
residual[3] = z[end][2] - 0.0
residual[4] = z[end][3] - 0.0
residual[5] = z[1][5] + n*z[1][3]
residual[6] = z[end][5] - 0.0
residual[7] = z[1][7] - 1.0
residual[8] = z[end][7] - 0.0
end
bvp1 = BVProblem(simplependulum!, bc1!, [0.,0.,0.,0.,0.,0.,1.,0.], tspan)
sol1 = solve(bvp1, Shooting(Tsit5()), dt=0.1)
THE ERROR I AM GETTING IS:
Closest candidates are:
(::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat at C:\Users\Shantanu\AppData\Local\Programs\Julia-1.7.2\share\julia\base\rounding.jl:200
(::Type{T})(::T) where T<:Number at C:\Users\Shantanu\AppData\Local\Programs\Julia-1.7.2\share\julia\base\boot.jl:770
(::Type{T})(::SymbolicUtils.Symbolic) where T<:Union{AbstractFloat, Integer, Complex{<:Integer}, Complex{<:AbstractFloat}} at C:\Users\Shantanu\.julia\packages\Symbolics\vQXbU\src\Symbolics.jl:135
...
Stacktrace:
[1] convert(#unused#::Type{Float64}, x::Num)
@ Base .\number.jl:7
[2] setindex!(A::Vector{Float64}, x::Num, i1::Int64)
@ Base .\array.jl:903
[3] simplependulum!(dz::Vector{Float64}, z::Vector{Float64}, p::SciMLBase.NullParameters, eta::Float64)
@ Main .\In[125]:31
[4] ODEFunction
@ C:\Users\Shantanu\.julia\packages\SciMLBase\nbKmA\src\scimlfunctions.jl:345 [inlined]
[5] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, SciMLBase.NullParameters, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, BVProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, typeof(simplependulum!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(bc1!), SciMLBase.StandardBVProblem, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, typeof(simplependulum!), LinearAlgebra.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.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, typeof(simplependulum!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(LinearAlgebra.opnorm), Nothing, CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, 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}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False})
@ OrdinaryDiffEq C:\Users\Shantanu\.julia\packages\OrdinaryDiffEq\ZBye7\src\perform_step\low_order_rk_perform_step.jl:627
[6] __init(prob::BVProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, typeof(simplependulum!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(bc1!), SciMLBase.StandardBVProblem, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, alg::Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, 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(LinearAlgebra.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.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ OrdinaryDiffEq C:\Users\Shantanu\.julia\packages\OrdinaryDiffEq\ZBye7\src\solve.jl:456
[7] #__solve#502
@ C:\Users\Shantanu\.julia\packages\OrdinaryDiffEq\ZBye7\src\solve.jl:4 [inlined]
[8] #solve_call#39
@ C:\Users\Shantanu\.julia\packages\DiffEqBase\U3LtB\src\solve.jl:155 [inlined]
[9] #solve_up#41
@ C:\Users\Shantanu\.julia\packages\DiffEqBase\U3LtB\src\solve.jl:182 [inlined]
[10] #solve#40
@ C:\Users\Shantanu\.julia\packages\DiffEqBase\U3LtB\src\solve.jl:168 [inlined]
[11] (::BoundaryValueDiffEq.var"#18#19"{Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:dt,), Tuple{Float64}}}, BVProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, typeof(simplependulum!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(bc1!), SciMLBase.StandardBVProblem, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, Shooting{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, BoundaryValueDiffEq.var"#1#2"}, typeof(bc1!)})(resid::Vector{Float64}, minimizer::Vector{Float64})
@ BoundaryValueDiffEq C:\Users\Shantanu\.julia\packages\BoundaryValueDiffEq\fnUX7\src\solve.jl:11
[12] (::NLSolversBase.var"#fj_finitediff!#21"{BoundaryValueDiffEq.var"#18#19"{Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:dt,), Tuple{Float64}}}, BVProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, typeof(simplependulum!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(bc1!), SciMLBase.StandardBVProblem, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, Shooting{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, BoundaryValueDiffEq.var"#1#2"}, typeof(bc1!)}, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:central}(), Float64}})(F::Vector{Float64}, J::Matrix{Float64}, x::Vector{Float64})
@ NLSolversBase C:\Users\Shantanu\.julia\packages\NLSolversBase\cfJrN\src\objective_types\oncedifferentiable.jl:138
[13] value_jacobian!!(obj::OnceDifferentiable{Vector{Float64}, Matrix{Float64}, Vector{Float64}}, F::Vector{Float64}, J::Matrix{Float64}, x::Vector{Float64})
@ NLSolversBase C:\Users\Shantanu\.julia\packages\NLSolversBase\cfJrN\src\interface.jl:124
[14] value_jacobian!!
@ C:\Users\Shantanu\.julia\packages\NLSolversBase\cfJrN\src\interface.jl:122 [inlined]
[15] trust_region_(df::OnceDifferentiable{Vector{Float64}, Matrix{Float64}, Vector{Float64}}, initial_x::Vector{Float64}, xtol::Float64, ftol::Float64, iterations::Int64, store_trace::Bool, show_trace::Bool, extended_trace::Bool, factor::Float64, autoscale::Bool, cache::NLsolve.NewtonTrustRegionCache{Vector{Float64}})
@ NLsolve C:\Users\Shantanu\.julia\packages\NLsolve\gJL1I\src\solvers\trust_region.jl:119
[16] trust_region (repeats 2 times)
@ C:\Users\Shantanu\.julia\packages\NLsolve\gJL1I\src\solvers\trust_region.jl:235 [inlined]
[17] nlsolve(df::OnceDifferentiable{Vector{Float64}, Matrix{Float64}, Vector{Float64}}, initial_x::Vector{Float64}; method::Symbol, xtol::Float64, ftol::Float64, iterations::Int64, store_trace::Bool, show_trace::Bool, extended_trace::Bool, linesearch::LineSearches.Static, linsolve::NLsolve.var"#27#29", factor::Float64, autoscale::Bool, m::Int64, beta::Int64, aa_start::Int64, droptol::Float64)
@ NLsolve C:\Users\Shantanu\.julia\packages\NLsolve\gJL1I\src\nlsolve\nlsolve.jl:26
[18] nlsolve(f::Function, initial_x::Vector{Float64}; method::Symbol, autodiff::Symbol, inplace::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ NLsolve C:\Users\Shantanu\.julia\packages\NLsolve\gJL1I\src\nlsolve\nlsolve.jl:52
[19] nlsolve(f::Function, initial_x::Vector{Float64})
@ NLsolve C:\Users\Shantanu\.julia\packages\NLsolve\gJL1I\src\nlsolve\nlsolve.jl:46
[20] #1
@ C:\Users\Shantanu\.julia\packages\BoundaryValueDiffEq\fnUX7\src\algorithms.jl:11 [inlined]
[21] __solve(prob::BVProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, typeof(simplependulum!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(bc1!), SciMLBase.StandardBVProblem, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, alg::Shooting{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, BoundaryValueDiffEq.var"#1#2"}; kwargs::Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:dt,), Tuple{Float64}}})
@ BoundaryValueDiffEq C:\Users\Shantanu\.julia\packages\BoundaryValueDiffEq\fnUX7\src\solve.jl:15