3

I am interested in using discrete variables that are not only dependent on the temporal variable t but also on a spatial variable x. For my needs I found a very useful example from here:

Clear[usol, u, t, x, λ];
usol = NDSolveValue[
  {
   D[u[t, x], t] == λ[t, x] D[u[t, x], x, x],
   u[0, x] == 0,
   u[t, 0] == Sin[t],
   u[t, 5] == 0,
   λ[0, x] == 1,
   WhenEvent[t > 5, λ[t, x] -> 1.25*λ[t, x]]
   },
  u,
  {t, 0, 10},
  {x, 0, 5},
  DiscreteVariables -> λ]
Plot3D[usol[t, x], {t, 0, 10}, {x, 0, 5}, PlotRange -> All]
NIntegrate[usol[1, x], {x, 0, 5}] (*This evaluates to 0.669665*)

According to the questioner this example worked for him. Unfortunately when I try this code I get an NDSolveValue:disto error. In the help page for discrete variables it can be found:

For partial differential equations, discrete variables can depend only on the temporal independent variable in a method of lines semi-discretization.

So in principle λ[t,x] should not work but λ[t]. Am I wrong here? Normally I would go along with the official help page, but as this feature would be very helpful for me I do not give up hope. :-)

Sebbo
  • 175
  • 8
  • In v9.0.1 it works, but apparently λ[t,x] is corrected to λ[t] internally: http://i.stack.imgur.com/HbNTY.png What's interesting is, if one directly use λ[t], dvlen warning will come out. – xzczd Oct 18 '16 at 15:01
  • Just tested on Wolfram Cloud, seems that at least in v11, the second argument of NDSolve should be {u, λ}, but according to the example in the document, the λ should be omissible! Maybe it should be considered as a bug? – xzczd Oct 18 '16 at 15:14
  • Thank you for your investigations. It is of course a dissapointment that λ[t,x] cannot be used that way but at least this gives me some clarity. – Sebbo Oct 19 '16 at 08:16
  • I think considering the working mechanism of "method of lines", It's natural that DiscreteVariables can't be spatial variable. Maybe you can talk a little more about what you're trying to achieve? – xzczd Oct 22 '16 at 03:28

0 Answers0