# NDSolve Surface Plot to Compare Initial Values

I am trying to solve a system of differential equations which model reaction kinetics using NDSolve. I would like to generate a surface-plot of the function value as a function of time and the initial value of one of the functions. For example, suppose I want to solve

NDSolve[{x'[t] == y[t], y'[t] == -x[t], x[0] == 1, y[0] == c}, {x, y}, {t, 0, 10}]


where c is a parameter that I vary. In my case, the solution can only be found numerically; no analytical solutions exist. I want a surface plot of y(t,c). Does anyone know of an easy way to do this? I haven't found much help online.

• Have you seen Plot3D[]? Mar 9, 2016 at 2:54
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Mar 9, 2016 at 3:20
• ParametricNDSolve. Mar 9, 2016 at 3:21
• To be clear; my system can not be solved analytically -- I gave an example to clarify my meaning, but it is not the system I am working with, and I don't think the output from NDSolve is compatible with Plot3D ParametricNDSolve is more along the lines of what I am looking for; is there a version that lets you create a surface plot? Mar 9, 2016 at 4:09
• Well, you could use a slight change of march's suggestion; that is, look up ParametricNDSolveValue[]; you should be able to use that with Plot3D[]. Mar 9, 2016 at 4:10

## 1 Answer

I guess I can post an answer at this point (with a hat tip to march):

pf = ParametricNDSolveValue[{x'[t] == y[t], y'[t] == -x[t], x[0] == 1, y[0] == c},
y, {t, 0, 10}, c];

Plot3D[pf[c][t], {t, 0, 10}, {c, 0, 4}]


• Does ParametricNDSolveValue still solve for both x and y under the hood, just returns only the solution for y? Mar 9, 2016 at 13:17
• I believe so (it's a coupled DE system after all); since only y was needed, this is reflected in the second argument of ParametricNDSolveValue[]. Mar 9, 2016 at 13:28
• It seems to give identical results either way, though I wouldn't trust MMA to know that the list of functions is {x,y} without explicitly being told so. Mar 9, 2016 at 13:31