-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UndefRefError: access to undefined reference #20
Comments
I'm not sure if this answers the question, but I think your problem is related to the way you type the equations. If I doing the following: julia> a = 1; b=-1;
julia> periodic_orbit(t,x) = [x[1](x[1]-a),b]
periodic_orbit (generic function with 1 method)
julia> periodic_orbit2(t,x) = [x[1](x[1]-a),b*x[2]]
periodic_orbit2 (generic function with 1 method) I get errors: julia> periodic_orbit(0.0, [0.0, 0.0])
ERROR: MethodError: objects of type Float64 are not callable
in periodic_orbit(::Float64, ::Array{Float64,1}) at ./REPL[13]:1
julia> periodic_orbit(0.0, [0.0, 0.0])
ERROR: MethodError: objects of type Float64 are not callable
in periodic_orbit(::Float64, ::Array{Float64,1}) at ./REPL[13]:1
I do not get the errors if I define the equations of motion for example as: |
Hi, @blas-ko! Glad you're interested in TaylorIntegration! In Julia 0.5, if I try to run using TaylorSeries, TaylorIntegration
a = 1; b=-1;
periodic_orbit2(t,x) = [x[1]*(x[1]-a),b]
x0 = [0.01, 0.005]
p = set_variables("ξ", numvars=2, order=15)
x0TN = x0+p
t0 = 0.0; Δt = 0.1; t = 1.0; tr = t0:Δt:t
@time xv = taylorinteg(periodic_orbit2,x0TN,tr,15,1.0e-15); Then I get the following error: BoundsError: attempt to access 1-element Array{TaylorSeries.TaylorN{Float64},1} at index [2]
in getindex(::Array{TaylorSeries.TaylorN{Float64},1}, ::Int64) at ./array.jl:386
in jetcoeffs!(::#periodic_orbit2, ::Float64, ::Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}) at /Users/Jorge/TaylorIntegration.jl/src/jettransport.jl:54
in taylorstep!(::Function, ::Float64, ::Array{TaylorSeries.TaylorN{Float64},1}, ::Int64, ::Float64) at /Users/Jorge/TaylorIntegration.jl/src/jettransport.jl:147
in #taylorinteg#14(::Int64, ::Function, ::Function, ::Array{TaylorSeries.TaylorN{Float64},1}, ::FloatRange{Float64}, ::Int64, ::Float64) at /Users/Jorge/TaylorIntegration.jl/src/jettransport.jl:412
in taylorinteg(::Function, ::Array{TaylorSeries.TaylorN{Float64},1}, ::FloatRange{Float64}, ::Int64, ::Float64) at /Users/Jorge/TaylorIntegration.jl/src/jettransport.jl:392 But if instead I try to run @time xv = taylorinteg(periodic_orbit3,x0TN,tr,15,1.0e-15); where periodic_orbit3(t,x) = [x[1]*(x[1]-a),b*one(x[1])] Then everything seems to work fine (note the 2-element Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}:
- 0.0099 - 0.98 ξ₁ + 1.0 ξ₁² + 𝒪(‖x‖¹⁶) + 𝒪(t¹⁶)
- 1.0 + 𝒪(‖x‖¹) + 𝒪(t¹) whereas running 2-element Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}:
- 0.0099 - 0.98 ξ₁ + 1.0 ξ₁² + 𝒪(‖x‖¹⁶) + 𝒪(t¹⁶)
- 1.0 + 𝒪(‖x‖¹⁶) + 𝒪(t¹⁶) the difference being in the order of the second |
Does the problem persist? |
Hi, @blas-ko! Any update on this issue? 😄 |
Hey! Sorry for the long long delay on answering. A solution may be a kind of promotion in the order of the polynomials in the array, where it takes the higher order so none of the internal functions have problems with this. I don't know if this may the integrator lose some generality, but if it doesn't I can do a PR with this little change. |
@blas-ko Sorry for the long silence, and thanks again for opening this issue; yesterday @PerezHz reminded me about it. What I'd like to point out here is that, indeed, things are messed up due to some ambiguous behavior related to default promotion of a simple number to a The following is the simplest case I could construct: julia> using TaylorSeries, TaylorIntegration
julia> tv = 0.0:0.25:1.0 ;
julia> xdot(t,x) = 3.0;
julia> xv = taylorinteg(xdot, 0.0, tv, 20, 1.0e-20)
5-element Array{Float64,1}:
0.0
0.785268
1.57054
2.3558
3.14107 Notice that there is no error thrown in this case, but the result is simply wrong, and it is not related with the order or the absolute tolerance used. The correct result should be (x(t) = 3*t) the vector The problem is, as @PerezHz points out, related to the promotion of a constant to a Taylor1 for this case, which happens internally, probably inside of I think the problem comes from @blas-ko, please go ahead and send us your PR. Thanks again! |
Hi, @blas-ko! Do you have yet an idea of an implementation to solve this issue? |
I've discussed with @lbenet offline and it seems that #31 solves this issue when julia> using TaylorSeries, TaylorIntegration;
julia> a,b = 1., 0.5;
julia> function periodic_orbit1!(t,x,dx)
dx[1] = x[1]*(x[1]-a)
dx[2] = b
nothing
end;
julia> ξ1, ξ2 = set_variables("ξ", numvars=2, order=15);
julia> q0 = [ξ1, ξ2 + 0.05];
julia> U, dof = eltype(q0), length(q0);
julia> dx = Array{Taylor1{U}}(dof) #note this is a Taylor1{TaylorN{U}}
2-element Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}:
#undef
#undef
julia> periodic_orbit1!(0.0,q0,dx)
julia> dx
2-element Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}:
- 1.0 ξ₁ + 1.0 ξ₁² + 𝒪(‖x‖¹⁶) + 𝒪(t¹)
0.5 + 𝒪(‖x‖¹) + 𝒪(t¹) Note that, by construction of The only things I can think about are:
My suggestion is to use |
Well, I definitely agree with you @blas-ko, convert{T<:Number}(::Type{TaylorN{T}}, b::T) =
TaylorN( [HomogeneousPolynomial([b], 0)], get_order()) instead of what is currently defined: convert{T<:Number}(::Type{TaylorN{T}}, b::T) =
TaylorN( [HomogeneousPolynomial([b], 0)], 0) #note the 0 instead of get_order() then the TaylorN-related part of the problem is solved: julia> using TaylorSeries, TaylorIntegration;
INFO: Recompiling stale cache file /Users/Jorge/.julia/lib/v0.6/TaylorSeries.ji for module TaylorSeries.
julia> a,b = 1., 0.5;
julia> function periodic_orbit1!(t,x,dx)
dx[1] = x[1]*(x[1]-a)
dx[2] = b
nothing
end;
julia> ξ1, ξ2 = set_variables("ξ", numvars=2, order=15);
julia> q0 = [ξ1, ξ2 + 0.05]
2-element Array{TaylorSeries.TaylorN{Float64},1}:
1.0 ξ₁ + 𝒪(‖x‖¹⁶)
0.05 + 1.0 ξ₂ + 𝒪(‖x‖¹⁶)
julia> U, dof = eltype(q0), length(q0);
julia> dx = Array{Taylor1{U}}(dof)
2-element Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}:
#undef
#undef
julia> periodic_orbit1!(0.0,q0,dx)
julia> dx
2-element Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}:
- 1.0 ξ₁ + 1.0 ξ₁² + 𝒪(‖x‖¹⁶) + 𝒪(t¹)
0.5 + 𝒪(‖x‖¹⁶) + 𝒪(t¹) #note the 16-th order TaylorN here At least now the order of the TaylorN has the correct value. @lbenet: Incidentally, I executed TaylorSeries.jl tests on my machine with this change, and everything runs smoothly! 👌 I think this gives more consistency to conversions from constants to TaylorNs, what do you think? Now, returning to the original problem, unfortunately, this is not enough to solve it: julia> @time tv, xv = taylorinteg(periodic_orbit1!, q0, 0.0, 1.0, 28, 1e-20);
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] jetcoeffs!(::#periodic_orbit1!, ::Float64, ::Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}, ::Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}, ::Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}, ::Array{Float64,1}) at /Users/Jorge/TaylorIntegration.jl/src/explicitode.jl:85
[2] taylorstep!(::Function, ::Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}, ::Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}, ::Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}, ::Float64, ::Float64, ::Array{TaylorSeries.TaylorN{Float64},1}, ::Int64, ::Float64, ::Array{Float64,1}) at /Users/Jorge/TaylorIntegration.jl/src/explicitode.jl:189
[3] #taylorinteg#4(::Int64, ::Function, ::Function, ::Array{TaylorSeries.TaylorN{Float64},1}, ::Float64, ::Float64, ::Int64, ::Float64) at /Users/Jorge/TaylorIntegration.jl/src/explicitode.jl:335
[4] taylorinteg(::Function, ::Array{TaylorSeries.TaylorN{Float64},1}, ::Float64, ::Float64, ::Int64, ::Float64) at /Users/Jorge/TaylorIntegration.jl/src/explicitode.jl:313 I also realized that evaluating
In order to prove that this indeed the method that is called, I tried changing the julia> periodic_orbit1!(0.0,q0,dx)
julia> dx
2-element Array{TaylorSeries.Taylor1{TaylorSeries.TaylorN{Float64}},1}:
- 1.0 ξ₁ + 1.0 ξ₁² + 𝒪(‖x‖¹⁶) + 𝒪(t¹)
0.5 + 𝒪(‖x‖¹⁶) + 𝒪(t⁶) #Note the t^6!!! This tells us that the problem indeed has to do with this I also tried overloading setindex!{T<:Number}(a::Array{Taylor1{TaylorN{T}},1}, x::T, n::Int) = a[n] = Taylor1( TaylorN( [HomogeneousPolynomial([x], 0)], get_order()), a[n].order) before calling So, yeah, it'd be tricky to turn this around since, as has been said before, as it is written now, the code has no way to tell what the "good" Taylor1 order is for the constant |
Thanks for the ping, @lbenet! I agree to close this |
Great!! I agree also :) |
I'm trying to model a differential equation (in polar coordenates) that has a periodic orbit in
r=a
with
a
andb
constants.Integrating this using
with
outputs the following error
if instead
is used, the integrator runs as it should.
I believe this has something to do with not making any operations for the second element of the array of the
periodic_orbit
function, but honestly I have no idea why his wouldn't work.The text was updated successfully, but these errors were encountered: