0
$\begingroup$

I am trying to use ParametricNDSolve to solve a set of ODEs, but I want to give a range for the parameter before solving the equations. How can I constrain the range of the parameter that ParametricNDSolve should use?

For example, in the equation below, I want to try and solve the ODEs for a between 4 and 6 only.

ParametricNDSolve[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}]
$\endgroup$
1
  • 2
    $\begingroup$ Why? With sol = y /. ParametricNDSolve[....] you can just sol[4] to have a=4 and also for other a that you're interested in. $\endgroup$
    – corey979
    Jan 10, 2017 at 21:47

1 Answer 1

3
$\begingroup$

Your question seems to raise a non-issue. The parametric function returned from evaluating

 yF = ParametricNDSolveValue[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}]

is good for any value of a in your range of interest. This is demonstrated by

LogPlot[Evaluate @ Table[yF[a][t], {a, 4, 6, .5}], {t, 0, 10}, PlotRange -> All]

plot

If, for further calculations, you have the need to constrain evaluation to a in the stated range, you can derive a constrained family of functions like so:

yCF[a_ /; 4 <= a <= 6] := YF[a]

yCF will only accept parameter values in stated range and return unevaluated for any other values.

$\endgroup$
2
  • $\begingroup$ Thank you for your reply. Now if I have the code below: d = {{9.721036901*10^-7, 0.80119823*10^-6}, {9.728704323*10^-7, 0.83015194*10^-6}, {9.728577185000001*10^-7, 0.857031534*10^-6},{9.728430487000002*10^-7, 0.88804645*10^-6}, {9.733506242*10^-7, 0.914930348*10^-6}, {9.733359543*10^-7, 0.945945264*10^-6}}; b = Interpolation[d, InterpolationOrder -> 1]; bb = b[a]*10^-4; yF = ParametricNDSolveValue[{y'[t] == bb y[t], y[0] == 1}, y, {t, 0, 10}, {a}], Mathematica is solving the DE but Ican't plot anything. $\endgroup$ Jan 10, 2017 at 22:37
  • $\begingroup$ @math_enthusiast. That is an entirely different question. You need to post it as new question. $\endgroup$
    – m_goldberg
    Jan 10, 2017 at 23:20

Your Answer

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

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