Can I use user defined data types with ODE?

Can I use user defined data type with ODE function?

 mutable struct ud
     a::Float64
     b::Float64
end

function od!(dx,x,t)
    dx.= [1, x.a ];
end

ic = ud(1.0,2.0);
prob=ODEProblem(od!,ic,(0.0,1.2));
sol1=solve(prob1, Tsit5(), reltol=1e-12, abstol=1e-12);

This currently does not work. Is it possible to design something like this? If so how?

Yes, but you will probably need to make your struct an AbstractArray type. You could use a FieldVector (see API · StaticArrays.jl) from StaticArrays.jl.

3 Likes

Thanks that answers my question! :smiley: