I have a 3-D data set (linked in the comment below) obtained via numerical integration. I would like to generate an interpolating function, and then use this function to numerically solve an ODE. For reference, the 3-D function looks like this:

enter image description here

The data set is used to create the interpolated function:

int = Interpolation[Flatten[Data1,1]]

I then sought to use NDSolve for the ODE xtraj'[T]==int[X,T], making the replacement X->xtraj[T]. I then sought to solve the ODE for T=[-1,1] for example. However I have not been successful in plotting the solution; using ParametricPlot does not yield anything.

ode = {xtraj'[T] == int[X, T] /. {X -> xtraj[T]}, xtraj[-2] == -2}
trajectories = NDSolve[ode, xtraj[T], {T, -1, 1}]
ParametricPlot[trajectories, {T, -1, 1}]

Any help as to why the solution is not plotting, or fixes re: syntax errors or a better solution would be much appreciated.


1 Answer 1


Assuming rational expressions inside the data I first create usable data and interpolationfunction

data = Import["...data1.txt", "Table"] ;
xyz = Map[N[ToExpression[#]] &, data];

int = Interpolation[xyz]
Plot3D[int[x, y], {x, -2, 2}, {y, -2, 2},PlotRange->All]

enter image description here

The ode is

ode = {xtraj'[T] == int[xtraj[T], T], xtraj[-2] == -2}

Hope I understand trajectories right

trajectories = NDSolveValue[ode, xtraj, {T, -2, 2}]
Plot[Evaluate[trajectories[T]], {T, -2, 2}]

enter image description here

  • $\begingroup$ Maybe I was incorrect in using ParametricPlot here... Thank you! $\endgroup$
    – j.foobles
    Nov 3, 2020 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.