0
$\begingroup$

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.

$\endgroup$
7
  • $\begingroup$ Have you seen Plot3D[]? $\endgroup$ Mar 9, 2016 at 2:54
  • $\begingroup$ 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! $\endgroup$
    – Michael E2
    Mar 9, 2016 at 3:20
  • 1
    $\begingroup$ ParametricNDSolve. $\endgroup$
    – march
    Mar 9, 2016 at 3:21
  • 1
    $\begingroup$ 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? $\endgroup$ Mar 9, 2016 at 4:09
  • 1
    $\begingroup$ 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[]. $\endgroup$ Mar 9, 2016 at 4:10

1 Answer 1

0
$\begingroup$

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}]

plot of a parametrized numerical solution

$\endgroup$
3
  • $\begingroup$ Does ParametricNDSolveValue still solve for both x and y under the hood, just returns only the solution for y? $\endgroup$
    – LLlAMnYP
    Mar 9, 2016 at 13:17
  • $\begingroup$ 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[]. $\endgroup$ Mar 9, 2016 at 13:28
  • $\begingroup$ 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. $\endgroup$
    – LLlAMnYP
    Mar 9, 2016 at 13:31

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.