ApproxFun: how to define initial conditions for a second-order ODE?

Hello,

I am struggling with the very basics of usage of ApproxFun package. I would like to use it solve the very simplest second-order linear initial value problem \ddot u(t) + \dot u(t) + u(t) = 0, u(0) = 1, \dot u(0) = 0, on the interval [0,1]. The examples on ApproxFun webpage do not give me much guidance - they either handle first-order problems or boundary value problems.

This is what I am trying in Julia:

using ApproxFun, LinearAlgebra
t₀ = 0.0; t₁ = 1.0; t = Interval(t₀,t₁);

B0 = Evaluation(Chebyshev(t),t₀)
B1 = Evaluation(Chebyshev(t),t₀,1)
B = [B0;B1]

x₀ = 1.0; v₀ = 0.0; u₀ = [x₀;v₀]

D = Derivative(t); D2 = Derivative(t,2);
N = D2 + D + I;

u = [B;N]\[u₀,0]

The error after the last line is

ERROR: LoadError: MethodError: ApproxFun.setdomain(::ConstantSpace{ApproxFun.AnyDomain,ApproxFun.UnsetNumber}, ::ApproxFun.AnyDomain) is ambiguous. Candidates:
  setdomain(A::ConstantSpace{DD,R}, d) where {DD, R} in ApproxFun at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Fun/Space.jl:511
  setdomain(sp::Space{D,R} where R, d::D) where D<:Domain in ApproxFun at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Fun/Space.jl:66
Possible fix, define
  setdomain(::ConstantSpace{D<:Domain,R}, ::D<:Domain)
Stacktrace:
 [1] ApproxFun.SumSpace(::ConstantSpace{ApproxFun.AnyDomain,ApproxFun.UnsetNumber}, ::ApproxFun.ArraySpace{ConstantSpace{ApproxFun.AnyDomain,Float64},1,ApproxFun.AnyDomain,Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Spaces/Modifier/SumSpace.jl:168
 [2] ⊕(::ConstantSpace{ApproxFun.AnyDomain,ApproxFun.UnsetNumber}, ::ApproxFun.ArraySpace{ConstantSpace{ApproxFun.AnyDomain,Float64},1,ApproxFun.AnyDomain,Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Spaces/Modifier/Modifier.jl:9
 [3] union_rule(::ConstantSpace{ApproxFun.Point{Float64},Float64}, ::ApproxFun.ArraySpace{ConstantSpace{ApproxFun.AnyDomain,Float64},1,ApproxFun.AnyDomain,Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Spaces/ConstantSpace.jl:111
 [4] conversion_rule(::ConstantSpace{ApproxFun.Point{Float64},Float64}, ::ApproxFun.ArraySpace{ConstantSpace{ApproxFun.AnyDomain,Float64},1,ApproxFun.AnyDomain,Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Spaces/ConstantSpace.jl:102
 [5] conversion_type(::ApproxFun.ArraySpace{ConstantSpace{ApproxFun.AnyDomain,Float64},1,ApproxFun.AnyDomain,Float64}, ::ConstantSpace{ApproxFun.Point{Float64},Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Fun/Space.jl:177
 [6] defaultcoefficients(::Array{Float64,1}, ::ApproxFun.ArraySpace{ConstantSpace{ApproxFun.AnyDomain,Float64},1,ApproxFun.AnyDomain,Float64}, ::ConstantSpace{ApproxFun.Point{Float64},Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Fun/Space.jl:315
 [7] coefficients(::Array{Float64,1}, ::ApproxFun.ArraySpace{ConstantSpace{ApproxFun.AnyDomain,Float64},1,ApproxFun.AnyDomain,Float64}, ::ConstantSpace{ApproxFun.Point{Float64},Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Fun/Space.jl:338
 [8] coefficients at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Fun/Fun.jl:45 [inlined]
 [9] (::getfield(Base, Symbol("##3#4")){typeof(coefficients)})(::Tuple{Fun{ApproxFun.ArraySpace{ConstantSpace{ApproxFun.AnyDomain,Float64},1,ApproxFun.AnyDomain,Float64},Float64,Array{Float64,1}},ConstantSpace{ApproxFun.Point{Float64},Float64}}) at ./generator.jl:36
 [10] iterate at ./generator.jl:47 [inlined]
 [11] collect(::Base.Generator{Base.Iterators.Zip2{Array{Fun,1},ApproxFun.ArraySpace{Space{D,Float64} where D,1,ApproxFun.Point{Float64},Float64}},getfield(Base, Symbol("##3#4")){typeof(coefficients)}}) at ./array.jl:619
 [12] map at ./abstractarray.jl:2060 [inlined]
 [13] coefficients(::Array{Fun,1}, ::ApproxFun.ArraySpace{Space{D,Float64} where D,1,ApproxFun.Point{Float64},Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Spaces/Modifier/ArraySpace.jl:208
 [14] coefficients(::Array{Any,1}, ::ApproxFun.ArraySpace{Space{D,Float64} where D,1,ApproxFun.Point{Float64},Float64}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Spaces/Modifier/ArraySpace.jl:211
 [15] #\#184(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::ApproxFun.InterlaceOperator{Float64,1,Chebyshev{Segment{Float64},Float64},ApproxFun.ArraySpace{Space{D,Float64} where D,1,ApproxFun.Point{Float64},Float64},ApproxFun.CachedIterator{Tuple{Int64,Int64},ApproxFun.BlockInterlacer{Tuple{ApproxFun.Repeated{Bool}}}},ApproxFun.CachedIterator{Tuple{Int64,Int64},ApproxFun.BlockInterlacer{Tuple{ApproxFun.Take{ApproxFun.Repeated{Bool},Bool},ApproxFun.Take{ApproxFun.Repeated{Bool},Bool},ApproxFun.Repeated{Bool}}}},Tuple{ApproxFun.Infinity{Bool},ApproxFun.Infinity{Bool}}}, ::Array{Any,1}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Operators/ldiv.jl:11
 [16] \(::ApproxFun.InterlaceOperator{Float64,1,Chebyshev{Segment{Float64},Float64},ApproxFun.ArraySpace{Space{D,Float64} where D,1,ApproxFun.Point{Float64},Float64},ApproxFun.CachedIterator{Tuple{Int64,Int64},ApproxFun.BlockInterlacer{Tuple{ApproxFun.Repeated{Bool}}}},ApproxFun.CachedIterator{Tuple{Int64,Int64},ApproxFun.BlockInterlacer{Tuple{ApproxFun.Take{ApproxFun.Repeated{Bool},Bool},ApproxFun.Take{ApproxFun.Repeated{Bool},Bool},ApproxFun.Repeated{Bool}}}},Tuple{ApproxFun.Infinity{Bool},ApproxFun.Infinity{Bool}}}, ::Array{Any,1}) at /home/hurak/.julia/packages/ApproxFun/wFAIT/src/Operators/ldiv.jl:4
 [17] top-level scope at none:0
 [18] include_string(::Module, ::String, ::String) at ./loading.jl:1002
 [19] (::getfield(Atom, Symbol("##118#123")){String,String,Module})() at /home/hurak/.julia/packages/Atom/WSz3k/src/eval.jl:120
 [20] withpath(::getfield(Atom, Symbol("##118#123")){String,String,Module}, ::String) at /home/hurak/.julia/packages/CodeTools/hB4Hy/src/utils.jl:30
 [21] withpath at /home/hurak/.julia/packages/Atom/WSz3k/src/eval.jl:46 [inlined]
 [22] #117 at /home/hurak/.julia/packages/Atom/WSz3k/src/eval.jl:117 [inlined]
 [23] hideprompt(::getfield(Atom, Symbol("##117#122")){String,String,Module}) at /home/hurak/.julia/packages/Atom/WSz3k/src/repl.jl:76
 [24] macro expansion at /home/hurak/.julia/packages/Atom/WSz3k/src/eval.jl:116 [inlined]
 [25] (::getfield(Atom, Symbol("##116#121")){Dict{String,Any}})() at ./task.jl:85
in expression starting at /home/hurak/ownCloud/julia/Exploring ODEs/van_der_pol.jl:15

Obviously, I am failing and I am not able to decipher the error message. Any guidance?

Have you looked at the examples directory? There’s a 10th order one there.

https://github.com/JuliaApproximation/ApproxFunExamples/blob/master/ODEs/tenthorderODE.jl

1 Like

But that is a BVP, isn’t it? If fact, this is the example that I took the inspiration from for what I show above.

Ah sorry, my mistake.

Has this issue been resolved?

Can this issue be extended from the scalar ODE of a mass-spring-damper to the PDE of a wave equation \ddot{u} = Laplacian(u) + boundary and initial conditions?