DifferentialEquations.jl icon indicating copy to clipboard operation
DifferentialEquations.jl copied to clipboard

Conversion of solution to DataFrame not consistent with documentation

Open zimmermm opened this issue 6 years ago • 3 comments

If I take the example in 'Ordinary Differential Equations':

using DifferentialEquations, IterableTables, DataFrames
function parameterized_lorenz(du,u,p,t)
 du[1] = p[1]*(u[2]-u[1])
 du[2] = u[1]*(p[2]-u[3]) - u[2]
 du[3] = u[1]*u[2] - p[3]*u[3]
end
u0 = [1.0,0.0,0.0]
tspan = (0.0,1.0)
p = [10.0,28.0,8/3]
prob = ODEProblem(parameterized_lorenz,u0,tspan,p)
sol1 = solve(prob, Rosenbrock23())
df = DataFrame(sol1)

The timestamps appear as column labels and the components of the solution vector as rows! The expected behaviour is to have a column 'timestamp' and additional columns for each component of the solution vector u.

zimmermm avatar May 08 '19 13:05 zimmermm

Yes, it seems to be transposed. Luckily the transpose works: df = DataFrame(sol1'). https://github.com/queryverse/IterableTables.jl/issues/92 takes a peak into this. Someone who knows the data iterators might need to handle this.

ChrisRackauckas avatar May 09 '19 00:05 ChrisRackauckas

Ok, thanks for the workaround. Suppose I have a function that does some kind of analysis on an ODESolution and first converts the solution to a DataFrame, how would I check (programmatically) whether I have to transpose the solution or not.

zimmermm avatar May 09 '19 09:05 zimmermm

I think it will always be incorrect, since it broke with a DataFrames update.

ChrisRackauckas avatar May 09 '19 15:05 ChrisRackauckas