Group Abstract Group Abstract

Message Boards Message Boards

1
|
8.5K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

ParametricNDSolve and Manipulate

Posted 10 years ago

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}]
POSTED BY: Chris Smith
2 Replies
Posted 10 years ago

Thank you! Your solution works just fine!!

POSTED BY: Updating Name

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}]
POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard