1
$\begingroup$

when i use ParametricNDSolve, the output is not a explicit function, for example:

sol = ParametricNDSolve[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}];
The output is ->   {y -> ParametricFunction[ <> ]}

this output just says that y is a parametric function, but i need to know explicit form of y. how can i obtain y function in terms of t and a?

$\endgroup$
  • 1
    $\begingroup$ Nope, ParametricNDSolve[] implements numerical (not symbolical) methods $\endgroup$ – Dr. belisarius Dec 14 '14 at 6:10
  • 1
    $\begingroup$ DSolve solves this simple ODE symbolically. It will solve many ODEs, but it cannot solve all ODEs. $\endgroup$ – Michael E2 Dec 14 '14 at 13:05
3
$\begingroup$

One interpretation of the question is how to construct a solution that is explicitly a function the independent variable and the parameters as arguments. Here is one way:

solFN = Block[{y, a}, 
  Function @@ 
    {{t, a}, ParametricNDSolveValue[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}][a][t]}
  ]
(*  Function[{t, a}, ParametricFunction[ <> ][a][t]]  *)

solPFN[1, 3]
(*  20.0855  *)

The use of Block can be omitted in certain cases. What it does is temporarily clear y, a, and t of any values they have, so that the solution is computed in terms of the symbols. Inside Function the symbols are localized.

Another way to interpret the question is how to find an explicit symbolic solution. For that, one needs DSolve or DSolveValue:

solFN = Block[{y, a, t},
         Function @@ {{t, a}, DSolveValue[{y'[t] == a y[t], y[0] == 1}, y[t], t]}
         ]
(*  Function[{t, a}, E^(a t)]  *)

solFN[t, 3]
(*  E^(3 t)  *)
$\endgroup$
  • $\begingroup$ wouldn't it be much easier to just do solution = ParametricNDSolveValue[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}]? Then solution[0.5] gets the solution as an interpolating function for e.g. a=0.5 and solution[0.5][5] evaluates this for t=5... $\endgroup$ – Albert Retey Dec 15 '14 at 22:33
  • $\begingroup$ @AlbertRetey I assumed the OP realized this but wanted the solution as an explicit function of two arguments, t and a (where I interpreted "explicit" as above). I don't know why it would be desired in this form. Perhaps it's being passed to another function that requires it. E.g. Apply or MapThread. It might seem simpler to use solPFN = psol[#2][#1] &. where psol is the output of ParametricNDSolveValue, but I thought using symbols t and a for the parameters would make it clearer to OP what they represent. $\endgroup$ – Michael E2 Dec 15 '14 at 22:45
  • $\begingroup$ I might point out that by default ParameterNDSolve will return a ParametricFunction that caches its solutions, so that for a given a, the differential equation is integrated only once. (This is true for the solution in my answer.) $\endgroup$ – Michael E2 Dec 15 '14 at 22:47
  • 1
    $\begingroup$ OK. I understand, but I think it would make sense to point out that what is returned can actually be used in a straightforward way. I didn't understand the OPs question like that, but the question isn't exactly clear :-). $\endgroup$ – Albert Retey Dec 16 '14 at 14:22
  • $\begingroup$ @AlbertRetey Maybe the OP will clarify and I can update. Or maybe I've totally missed the point and will delete. $\endgroup$ – Michael E2 Dec 16 '14 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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