Based on this answer, I understand how to use a one dimensional compiled function in NDSolve. Mathematica NDSolve and 'Compile'?
I'd like to be able to use a d-dimensional compiled function f
, in the same way.
f
would be a vector-valued function which returns a vector, somthing like this:
f = Compile[{{x, _Real, 1}}, x]
But imagine that it's costly to evaluate.
I've dreamed up some syntax which I know doesn't work, but which kind of says what I want to happen:
rhs[x_?VectorQ[#, NumericQ]] := f[x]
NDSolve[Join[Thread[Table[x[i]'[t],{i,d}]-rhs[Table[x[i][t],{i,d}]]==0],initialconditions], Table[x[i][t],{i,d}], {t, 0, 1}]
I know that the above code won't work, because Mathematica won't know how to add together the vector of derivatives and the rhs
function until it's been evaluated numerically.
Does anybody know a syntax which works correctly for this?
Note that I can't just break down the vector function f
into d separate functions; it's costly to evaluate and I need to make sure that f
is called only once each time its components are accessed for a given value of x.
NDSolve[{x'[t] == f[t], x[0] == array}, x, {t, 0, 1},...]
wherearray
is of dim.d
. $\endgroup$