0
$\begingroup$

I am facing the following issue; I have the solution of a ParametricNDSolveValue and would like to plot several solutions with varying parameter in the same Manipulate to see qualitative differences. It works just fine when I only plot one function, but as soon as I try to pass multiple functions in a list I get an empty manipulate. I realize that this is probably just a syntax error, however I couldn't make it work. This is my code:

Diffus[x_] =  
  Piecewise[{{h1, 
      x < x1}, {((h2 - h1)/2)*Cos[(Pi/(x2 - x1))*x] + (h1 + h2)/2, 
      x1 <= x < x2}, {h2, x >= x2}}] /. {x1 -> 10, x2 -> 12, h1 -> 1, 
    h2 -> 20};
NeuB = NeumannValue[0, x == 0 || x == 30];
molfem[measure_ : Automatic] := {"MethodOfLines", 
   "SpatialDiscretization" -> {"FiniteElement", 
     "MeshOptions" -> MaxCellMeasure -> measure}};
SinglePeakParam[x_, h_] = 
  Piecewise[{{h1,x < x1}, {(-(h2 - h1)/2)*Cos[(Pi/(x2 - x1))*x] + ((h2 + h1)/2),x1<=x<x2},
{((h3 - h2)/2)*Cos[(Pi/(x3 - x2))*x] + ((h3 + h2)/2),x2 <= x < x3},
 {h3, x3 <= x}}] /.{x1 -> 10, x2 -> 11, x3 -> 12,h1 -> 5, h2 -> h, h3 -> 10};
ClearAll[P2, pde2];
pde2 = D[P2[x, t], t] + 
    D[(-D[P2[x, t], x]*Diffus[x] - 
       P2[x, t]*D[SinglePeakParam[x, h], x]*Diffus[x]), x] == NeuB;
Evals = ParametricNDSolveValue[{pde2, 
   P2[x, 0] == UnitStep[x - 12]/18}, 
  P2[x, t], {x, 0, 30}, {t, 0, 500}, {h}, Method -> molfem[0.01]];
Eval11[x_, t_] = Evals[11];
Eval12[x_, t_] = Evals[12];
Eval13[x_, t_] = Evals[13];
Eval14[x_, t_] = Evals[14];
Eval15[x_, t_] = Evals[15];
Eval16[x_, t_] = Evals[16];
Manlist = {Eval11[x, t], Eval12[x, t], Eval13[x, t], Eval14[x, t], 
  Eval15[x, t], Eval16[x, t]};
Manipulate[
 Plot[Manlist, {x, 0, 15}, PlotRange -> {0, 0.5}], {t, 0, 100}];

However, I have also tried the following code for the Manipulate;

Manipulate[
 Plot[Evaluate[Table[Evals[h][x, t], {h, {11, 12, 13, 14, 15, 16}}]], {x, 
   0, 15}, PlotRange -> {0, 0.5}], {t, 0, 100}]

Which also produced an empty Manipulate. I would like to understand what is going on, especially since the latter code has worked for me before. Thank you very much!

$\endgroup$
2
  • $\begingroup$ "molfem" is nowhere defied. $\endgroup$ Commented Apr 15, 2024 at 9:45
  • $\begingroup$ Sorry, I defined it earlier in the notebook. Put it where it should be $\endgroup$ Commented Apr 15, 2024 at 11:00

1 Answer 1

1
$\begingroup$

You have a problem with localization of variables x and t. Try the following:

Manlist[x_, t_] = {Eval11[x, t], Eval12[x, t], Eval13[x, t], 
   Eval14[x, t], Eval15[x, t], Eval16[x, t]};
Manipulate[
  Plot[Manlist, {x, 0, 15}, PlotRange -> {0, 0.5}], {t, 0, 100}];

![enter image description here

$\endgroup$
1
  • $\begingroup$ That did it for me! Thank you! $\endgroup$ Commented Apr 15, 2024 at 13:39

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.