# Solving ODE without explicit expression for the system

I have a system of differential equations, where $$\mathbf{y}'(x)=\mathbf{f}(\mathbf{y})$$ but I don't have an explicit expression for $f$, in fact I have to solve a linear system of equations to obtain $\mathbf{f}(\mathbf{y})$ for any $\mathbf{y}(x)$. I know I can't do this with NDSolve which just requires a simple expression for the ODE system. I want a method, much like the Scipy ODE solver, that gets $\mathbf{y}'(x)$ by calling a Mathematica function (that I have defined) that gives $\mathbf{f}(\mathbf{y})$. Is there such a thing?

• I don't see why NDSolve couldn't do this. It would be helpful if you provided a simple example of what you're trying to do. – Carl Woll Nov 17 '17 at 17:57
• You might want to read up on using _?NumericQ to define your f(y). Try here for starters. But yeah, a simple, concrete example would help spur answers. – Chris K Nov 17 '17 at 18:54

Since the OP didn't provide an example, here is a made up function f:

A = RandomReal[1, {4,4}];
f[y:{__?NumericQ}] := LinearSolve[A, y]


Here's an ODE that uses f:

sol = NDSolve[{y'[x] == f[y[x]], y[0] == {1,2,3,4}}, y, {x,0,1}];
sol //OutputForm


{{y -> InterpolatingFunction[{{0., 1.}}, <>]}}

Finally, here is the value at $x=1$:

y[1] /. First @ sol


{-13.846, 3.39417, 17.1691, -3.79776}

• Sorry for the late reply. This is exactly the solution I was looking for. I'm surprised this isn't mentioned in the documentation for NDSolve – oweydd Nov 22 '17 at 13:24