JuliaDynamics / DynamicalSystems.jl

Award winning software library for nonlinear dynamics and nonlinear timeseries analysis

Home Page:https://juliadynamics.github.io/DynamicalSystemsDocs.jl/dynamicalsystems/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to print out the state vector inside the "eom" function?

ig-or opened this issue · comments

commented

Trying to print out some state vector components for debugging. After @printf, getting Errors like

Stacktrace:
 [1] fix_dec(::ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{cnh_tpt.cnhLoopParams,Float64,typeof(cnh_tpt.hcLoop)},Float64},Float64,4}, ::Int64, ::Array{UInt8,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Printf/src/Printf.jl:992 (repeats 79984 times)

how to convert state vector components to smth. like Float64?

function hcLoop(sv::SVector{4}, params::cnhLoopParams, t)
	x = sv[1]
        @printf "x = %.3f \n" x
using DynamicalSystems

function f(u, p, t)
    @show u
    return u
end

ds = ContinuousDynamicalSystem(f, [0.1, 0.1], nothing)

tr = trajectory(ds, 1.0)

this works for me:

julia> 
ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Nothing,Float64,typeof(f)},Float64},Float64,2}[Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Nothing,Float64,typeof(f)},Float64}}(0.1,1.0,0.0), Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Nothing,Float64,typeof(f)},Float64}}(0.1,0.0,1.0)]
u = [0.1, 0.1]
[0.1, 0.1]
u = [0.100161, 0.100161]
u = [0.10032754012385535, 0.10032754012385535]
u = [0.1009040495557949, 0.1009040495557949]
u = [0.10098482453597712, 0.10098482453597712]
u = [0.10100499687894175, 0.10100499687894175]
u = [0.10100501670841681, 0.10100501670841681]
u = [0.1020601322646853, 0.1020601322646853]
u = [0.10317098209099486, 0.10317098209099486]
u = [0.10708086871070818, 0.10708086871070818]
u = [0.1076402264448548, 0.1076402264448548]
u = [0.10778025312641576, 0.10778025312641576]
u = [0.10777580914103836, 0.10777580914103836]
u = [0.10975325970738052, 0.10975325970738052]
u = [0.11186772348627237, 0.11186772348627237]
u = [0.11943098742941127, 0.11943098742941127]
u = [0.1205375994227601, 0.1205375994227601]
u = [0.12081501594254732, 0.12081501594254732]
u = [0.12078532662732924, 0.12078532662732924]
u = [0.12339659287623253, 0.12339659287623253]
u = [0.1262065875037564, 0.1262065875037564]
u = [0.13632819106555924, 0.13632819106555924]
u = [0.13782422463429936, 0.13782422463429936]
u = [0.13819941761258156, 0.13819941761258156]
u = [0.13814374015461184, 0.13814374015461184]
u = [0.14178528671719673, 0.14178528671719673]
u = [0.14573994879888746, 0.14573994879888746]
u = [0.16013402260555076, 0.16013402260555076]
u = [0.16229459490701853, 0.16229459490701853]
u = [0.16283667594624307, 0.16283667594624307]
u = [0.16271902402664656, 0.16271902402664656]
u = [0.16754618121244047, 0.16754618121244047]
u = [0.17282164141303924, 0.17282164141303924]
u = [0.1921671357693794, 0.1921671357693794]
u = [0.19510351167562898, 0.19510351167562898]
u = [0.1958403742297839, 0.1958403742297839]
u = [0.19564138373304862, 0.19564138373304862]
u = [0.20208753453305506, 0.20208753453305506]
u = [0.20917644618016681, 0.20917644618016681]
u = [0.23536971285473424, 0.23536971285473424]
u = [0.23939093583000065, 0.23939093583000065]
u = [0.24040013435246885, 0.24040013435246885]
u = [0.24007090158850591, 0.24007090158850591]
u = [0.24854911772014557, 0.24854911772014557]
u = [0.2579145268366372, 0.2579145268366372]
u = [0.29271204922797783, 0.29271204922797783]
u = [0.29809895045649226, 0.29809895045649226]
u = [0.2994509255894264, 0.2994509255894264]
u = [0.2989526001553013, 0.2989526001553013]

Anything related to ForwardDiff comes because you have not written the Jacobian yourself, if you get system specific errors try writing down the Jacobian.

commented

Thanks for the answer! @show works.

Jacobian will not help me, while trying to investigate stupid issues like wrong units/models.
If there could be a way to convert this "ForwardDiff" into Float64, this would be very helpful. Need some way to export somehow intermediate results for debugging.

just use print instead of this weird macro and all should be okay. print and show, the Julia functions, are defined for everything by default. @printf probably only for Real numbers.

commented

Thanks!