For example,

ParametricNDSolve[{y'[t] == a y[t]}, y, t, {a}]

returns a ParametricFunction which is actually inexplicable:

strange ParametricFunction

How to understand it?

Edited: It should be noticed that it differs from

ParametricNDSolve[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}]
y[1] /. sol


ParametricNDSolve[{y'[t] == a y[t]}, y, t, {a}]
y[1] /. sol

returns warning messages:

  1. ParametricNDSolve::ndlim: Range specification t is not of the form {x, xend} or {x, xmin, xmax}.

  2. ParametricNDSolve::ndnco: The number of constraints (0) (initial conditions) is not equal to the total differential order of the system plus the number of discrete variables (1).

    I wonder why ParametricNDSolve runs on though there isn't any initial conditions or boundary conditions.

  • $\begingroup$ To start understanding it: what happens if you try evaluating it? $\endgroup$ – J. M. will be back soon May 18 '15 at 2:56
  • $\begingroup$ @J. M. Thank you for your attention! I don't know how to use it correctly. $\endgroup$ – WateSoyan May 18 '15 at 2:56
  • $\begingroup$ So, try something like ytest = y[1] /. sol, and then maybe try ytest[0]. $\endgroup$ – J. M. will be back soon May 18 '15 at 3:04
  • $\begingroup$ But help shows how to use the result? The examples all show how to use it. Is the question about how to use the result or something else? $\endgroup$ – Nasser May 18 '15 at 3:08
  • 1
    $\begingroup$ @WateSoyan I don't think there is anything wrong; the ParametricFunction object is constructed without actually solving the equation. Once we try to evaluate it for a numeric value of the parameter a, we see that there is an insufficient number of initial conditions. $\endgroup$ – ilian May 18 '15 at 13:00

ParametricNDSolve is a numerical solver. You need to give it enough numerical values for the parameters and domain that the solver can come up with a unique InterpolatingFunction representing the numerical solution of your equation.

First, your differential equation of course has a family of $y(t)$ functions as solutions. How can ParametricNDSolve choose one among those? You need to give the numerical solver boundary conditions. In this case I chose y[0] == 1 arbitrarily.

Similarly, you need to specify over which interval of the independent variable you would like a solution.

Putting those together:

sol = ParametricNDSolve[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}]

Let us now choose an explicit value for the parameter $a$, e.g. $0.3$:

yinstance = y[0.3] /. sol

This returns:

Mathematica graphics

Now we can plot this InterpolatingFunction, with $t$ ranging over the $(0,10)$ interval as specified in the call to the solver:

Plot[yinstance[t], {t, 0, 10}]

Mathematica graphics

  • $\begingroup$ Aw, I was hoping the OP would try the experiment himself of trying to evaluate a ParametricFunction[] sans initial conditions… :D (+1 nevertheless) $\endgroup$ – J. M. will be back soon May 18 '15 at 3:28
  • $\begingroup$ Sorry.I have posted my comparison between that with initial conditions or boundary conditions and that without them.But I wonder why ParametricNDSolve runs on though there isn't any initial conditions or boundary conditions... $\endgroup$ – WateSoyan May 18 '15 at 3:30
  • 1
    $\begingroup$ @J. M. oopsie! and here I come, like the proverbial bull in the china shop, and spoil all the fun! :-) I'll have to be honest though: those error messages are really not the most illuminating, and they have driven me up the wall a few times as well... $\endgroup$ – MarcoB May 18 '15 at 3:31
  • 1
    $\begingroup$ @WateSoyan I think that the catch is that no evaluation is actually attempted until you "force" it, e.g. by asking for a value etc. Having said that, I wholeheartedly agree with you there: it could fail A LOT more gracefully than that. I guess this is one more example of what I have seen the pro's refer to as Mathematica's "late to fail" philosophy. $\endgroup$ – MarcoB May 18 '15 at 3:33
  • 1
    $\begingroup$ @WateSoyan I guess that in a way it is a kind attitude from the software's standpoint. It won't fail and throw up on you until it's really sure that you are without hope ;-) $\endgroup$ – MarcoB May 18 '15 at 3:35

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.