# ParametricNDSolve and Manipulate

**URL:** <https://community.wolfram.com/t/parametricndsolve-and-manipulate/7615>\
**Category:** Questions\
**Tags:** physics\
**Created:** [January 6, 2016, 7:58am UTC](https://community.wolfram.com/t/parametricndsolve-and-manipulate/7615 "2016-01-06T07:58:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwieschendorf](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cwieschendorf](https://community.wolfram.com/u/cwieschendorf)\
**Post date:** [January 6, 2016, 7:58am UTC](https://community.wolfram.com/t/parametricndsolve-and-manipulate/7615/1 "2016-01-06T07:58:43Z")

</div>

Hello,

I have a problem using Manipulate to tweek a coupled differential equation system. Maybe someone can help me out with this. I try to give a brief explanation:

1. I defined a piecewise function which consist of 3 variables.
2. I let mathematica solve my differential equations which are also dependent on the above piecewise function. The parameters defined, are 2 of the 3 from the piecewise function above.
3. With Manipulate I try to plot the solutions of the coupled differential equations for different values of the parameters.

The outcome is the manipulate graphical window with only 1 of 3 expected plots. Does anyone see a mistake in my coding?

Best regards

```
q[t_, p_, tau_] = 
  Piecewise[{{Exp[-t/tau], 0 <= t <= p}, {Exp[-p/tau], p < t}}];

s = ParametricNDSolve[{alpha'[t] == 
    alpha[t]*(n[t] - q[t, p, tau]) - 1*alpha[t]/2100, 
   n'[t] == -n[t]*alpha[t], alpha[0] == 0.0001, n[0] == 1}, {n[t], 
  alpha[t]}, {t, 0, 5000}, {p, tau}]

Manipulate[
 Plot[Evaluate[{alpha[t]*100, n[t], q[t, p, tau]} /. s], {t, 0, 5000}, 
  PlotRange -> {{0, 5000}, {0, 2}}, 
  PlotLegends -> {"alpha[t]", "n[t]", "q[t]"}], {p, 0, 5000}, {tau, 1, 
  5000}]

```

---

<div class="post-metadata">

**Author:** ![mroge02](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mroge02/32/28775_2.png) [@mroge02](https://community.wolfram.com/u/mroge02)\
**Post date:** [January 6, 2016, 3:46pm UTC](https://community.wolfram.com/t/parametricndsolve-and-manipulate/7615/2 "2016-01-06T15:46:42Z")

</div>

You need to pass the parameter values to the parametric functions returned by `ParametricNDSolve`:

```
q[t_, p_, tau_] = Piecewise[{{Exp[-t/tau], 0 <= t <= p}, {Exp[-p/tau], p < t}}];

s = ParametricNDSolve[{
   alpha'[t] == alpha[t]*(n[t] - q[t, p, tau]) - 1*alpha[t]/2100, 
   n'[t] == -n[t]*alpha[t], alpha[0] == 0.0001, n[0] == 1},
 {n, alpha}, {t, 0, 5000}, {p, tau}]

Manipulate[
 Plot[Evaluate[{alpha[p, tau][t]*100, n[p, tau][t], q[t, p, tau]} /. s], {t, 0, 5000},
  PlotRange -> {{0, 5000}, {0, 2}}, PlotLegends -> {"alpha[t]", "n[t]", "q[t]"}],
 {p, 0, 5000}, {tau, 1, 5000}]

```

---

<div class="post-metadata">

**Author:** ![anon21378091](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@anon21378091](https://community.wolfram.com/u/anon21378091)\
**Post date:** [January 7, 2016, 5:31am UTC](https://community.wolfram.com/t/parametricndsolve-and-manipulate/7615/3 "2016-01-07T05:31:48Z")

</div>

Thank you! Your solution works just fine!!
