Skip to content

Conversation

giordano
Copy link
Contributor

@ChrisRackauckas
Copy link
Member

I think you should mention here that the default absolute tolerance is 1e-6 and default relative tolerance is 1e-3, so this matches quite well with the tolerance estimates. To get a more accurate solution, change the tolerance.

Other than that, looks great!

@giordano
Copy link
Contributor Author

Now I'm using a tighter tolerance in the tutorial, so that the plots are smoother, thanks for the tip

However, I've just realized that the second example still fails if tspan isn't a tuple of Measurements:

using DifferentialEquations, Measurements
g = 9.79 ± 0.02; # Gravitational constants
L = 1.00 ± 0.01; # Length of the pendulum
#Initial Conditions
u₀ = [0 ± 0, π / 60 ± 0.01] # Initial speed and initial angle
tspan = (0.0, 6.3)
#Define the problem
function simplependulum(du,u,p,t)
    θ  = u[1]
    dθ = u[2]
    du[1] = dθ
    du[2] = -(g/L)*θ
end
#Pass to solvers
prob = ODEProblem(simplependulum, u₀, tspan)
sol = solve(prob, Tsit5())

error message:

ERROR: LoadError: MethodError: no method matching Float64(::Measurement{Float64})
Closest candidates are:
  Float64(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:173
  Float64(::T<:Number) where T<:Number at boot.jl:725
  Float64(::Int8) at float.jl:60
  ...
Stacktrace:
 [1] Float64(::Measurement{Float64}) at ./deprecated.jl:468
 [2] ode_determine_initdt(::Array{Measurement{Float64},1}, ::Float64, ::Float64, ::Float64, ::Measurement{Float64}, ::Measurement{Float64}, ::typeof(DiffEqBase.ODE_DEFAULT_NORM), ::ODEProblem{Array{Measurement{Float64},1},Tuple{Float64,Float64},true,Nothing,ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::OrdinaryDiffEq.ODEIntegrator{Tsit5,Array{Measurement{Float64},1},Float64,Nothing,Float64,Float64,Float64,Array{Array{Measurement{Float64},1},1},ODESolution{Measurement{Float64},2,Array{Array{Measurement{Float64},1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Measurement{Float64},1},1},1},ODEProblem{Array{Measurement{Float64},1},Tuple{Float64,Float64},true,Nothing,ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Measurement{Float64},1},1},Array{Float64,1},Array{Array{Array{Measurement{Float64},1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Measurement{Float64},1},Array{Measurement{Float64},1},Array{Measurement{Float64},1},Array{Measurement{Float64},1},OrdinaryDiffEq.Tsit5ConstantCache{Measurement{Float64},Float64}}}},ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Measurement{Float64},1},Array{Measurement{Float64},1},Array{Measurement{Float64},1},Array{Measurement{Float64},1},OrdinaryDiffEq.Tsit5ConstantCache{Measurement{Float64},Float64}},OrdinaryDiffEq.DEOptions{Measurement{Float64},Measurement{Float64},Float64,Float64,typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(LinearAlgebra.opnorm),CallbackSet{Tuple{},Tuple{}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Nothing,Nothing,Int64,Array{Float64,1},Array{Float64,1},Array{Float64,1}},Array{Measurement{Float64},1}}) at ./logging.jl:311
 [3] auto_dt_reset!(::OrdinaryDiffEq.ODEIntegrator{Tsit5,Array{Measurement{Float64},1},Float64,Nothing,Float64,Float64,Float64,Array{Array{Measurement{Float64},1},1},ODESolution{Measurement{Float64},2,Array{Array{Measurement{Float64},1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Measurement{Float64},1},1},1},ODEProblem{Array{Measurement{Float64},1},Tuple{Float64,Float64},true,Nothing,ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Measurement{Float64},1},1},Array{Float64,1},Array{Array{Array{Measurement{Float64},1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Measurement{Float64},1},Array{Measurement{Float64},1},Array{Measurement{Float64},1},Array{Measurement{Float64},1},OrdinaryDiffEq.Tsit5ConstantCache{Measurement{Float64},Float64}}}},ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Measurement{Float64},1},Array{Measurement{Float64},1},Array{Measurement{Float64},1},Array{Measurement{Float64},1},OrdinaryDiffEq.Tsit5ConstantCache{Measurement{Float64},Float64}},OrdinaryDiffEq.DEOptions{Measurement{Float64},Measurement{Float64},Float64,Float64,typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(LinearAlgebra.opnorm),CallbackSet{Tuple{},Tuple{}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Nothing,Nothing,Int64,Array{Float64,1},Array{Float64,1},Array{Float64,1}},Array{Measurement{Float64},1}}) at /home/mose/.julia/packages/OrdinaryDiffEq/sJHbC/src/integrators/integrator_interface.jl:250
 [4] #__init#203(::Int64, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Nothing, ::Bool, ::Nothing, ::Bool, ::Bool, ::Nothing, ::Bool, ::Bool, ::Float64, ::Bool, ::Rational{Int64}, ::Nothing, ::Nothing, ::Int64, ::Rational{Int64}, ::Int64, ::Int64, ::Rational{Int64}, ::Bool, ::Int64, ::Nothing, ::Nothing, ::Int64, ::Float64, ::Float64, ::typeof(DiffEqBase.ODE_DEFAULT_NORM), ::typeof(LinearAlgebra.opnorm), ::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), ::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Int64, ::String, ::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), ::Nothing, ::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.__init), ::ODEProblem{Array{Measurement{Float64},1},Tuple{Float64,Float64},true,Nothing,ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Type{Val{true}}) at /home/mose/.julia/packages/OrdinaryDiffEq/sJHbC/src/solve.jl:267
 [5] __init(::ODEProblem{Array{Measurement{Float64},1},Tuple{Float64,Float64},true,Nothing,ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Type{Val{true}}) at /home/mose/.julia/packages/OrdinaryDiffEq/sJHbC/src/solve.jl:61
 [6] #__solve#202(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::ODEProblem{Array{Measurement{Float64},1},Tuple{Float64,Float64},true,Nothing,ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Type{Val{true}}) at /home/mose/.julia/packages/OrdinaryDiffEq/sJHbC/src/solve.jl:6
 [7] __solve at /home/mose/.julia/packages/OrdinaryDiffEq/sJHbC/src/solve.jl:6 [inlined] (repeats 3 times)
 [8] #solve#429(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::ODEProblem{Array{Measurement{Float64},1},Tuple{Float64,Float64},true,Nothing,ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5) at /home/mose/.julia/packages/DiffEqBase/sjhUa/src/solve.jl:29
 [9] solve(::ODEProblem{Array{Measurement{Float64},1},Tuple{Float64,Float64},true,Nothing,ODEFunction{true,typeof(simplependulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5) at /home/mose/.julia/packages/DiffEqBase/sjhUa/src/solve.jl:21
 [10] top-level scope at none:0
 [11] include at ./boot.jl:317 [inlined]
 [12] include_relative(::Module, ::String) at ./loading.jl:1038
 [13] include(::Module, ::String) at ./sysimg.jl:29
 [14] include(::String) at ./client.jl:398
 [15] top-level scope at none:0

@ChrisRackauckas
Copy link
Member

Missing norm definition and one missed convert change. DiffEqBase + OrdinaryDiffEq masters now handle it fine.

@ChrisRackauckas
Copy link
Member

Should work on updated versions.

@ChrisRackauckas
Copy link
Member

Looks fantastic!

@ChrisRackauckas ChrisRackauckas merged commit d4036f7 into SciML:master Sep 25, 2018
@giordano
Copy link
Contributor Author

I'm too late writing, but that's ok 😅

Before update: https://nbviewer.jupyter.org/github/giordano/DiffEqTutorials.jl/blob/7e3ccc6b73f2b2c5962f09a60723609741301e7b/PhysicalModels/NumberUncertainties.ipynb
After update (current version): https://nbviewer.jupyter.org/github/giordano/DiffEqTutorials.jl/blob/584f18d177b1bfd3a7893e98bbd07c1b53a33406/PhysicalModels/NumberUncertainties.ipynb

Yesterday I didn't pay much attention, but errorbars were probably wrong. There is no uncertainty on times, the only quantity with uncertatinty is half-life of Carbon-14, so I have no idea where those bars on x came from 😕 Current results look more OK, also the plot in Out[10] now shows difference between numerical and analytic solution smaller than the requested tolerance

@giordano giordano deleted the update-measurementsjl branch September 25, 2018 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants