-
-
Notifications
You must be signed in to change notification settings - Fork 49
Working on a matrix instead of vector #86
Comments
This should work. There is actually an example in test/Interface-tests.jl ( On Mi., 10. Feb. 2016 at 18:08, Gerson J. Ferreira [email protected]
|
You probably know this: often when working with ODE solvers, 2D (or ND) data is represented as a vector as far as the ODE solver is concerned. How |
Yes, reshape would work, but it makes a copy of the data, which could be slow. I was trying to avoid using reshape or rewriting the code in terms of a vector. It is just must simpler to evaluate the r.h.s. as it is now. The example on the link (https://github.com/JuliaLang/ODE.jl/blob/master/test/interface-tests.jl) is great. Is the trick defining a custom type? In my code y is matrix, while in the example it is the custom type CompSol. Here's a simple example that illustrate my question:
If I go with the first definition of
|
For normal arrays reshape does not copy:
but its copying semantics are unspecified. But otherwise you can also look at views, etc. But the scalar approach could be easiest. Actually, what happens if you just pass in a 2D array? Maybe that works as single dimensional indexing is defined. |
Beautiful!! I didn't know |
Cool. Close this if it is resolved. |
I'm not sure yet. My first attempt didn't work. But let me try again and I'll reply in a few days. |
Any luck? |
Not really. The workaround was getting clumsy, so I decided to solve the differential equation with a different method (using the split-step method instead of RK). But the problem seems to be on how the ODE package stores the output. In the code below I store the data at each time instant concatenating as an array of arrays. I believe this is similar to what ODE does, but somehow doesn't naturally works if the initial condition is a matrix.
|
Yes, you were right, it didn't work, except with |
I'm working on a 2D diffusion equation with a single time derivative on the l.h.s. and x and y derivatives on the r.h.s:
d[ f(x,y,t) ]/dt = H f(x,y,t)
Without using ODE, I solve this with simply as
f(x,y,t+1) = f(x,y,t) + dt H f(x,y,t)
And it is more efficient to write f(x,y,t) as a matrix with x as lines as y as columns. So my function F(f) receives f as a matrix and returns another matrix out=H.f. In F(f) I work out the space derivatives using Fourier transforms.
This is not compatible with the ODE code, right? ODE requires f to be a vector.
Would it be difficult to generalize ODE to accept f(x,y,t) to be a matrix?
The text was updated successfully, but these errors were encountered: