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. :-)
λ[t,x]is corrected toλ[t]internally: http://i.stack.imgur.com/HbNTY.png What's interesting is, if one directly useλ[t],dvlenwarning will come out. – xzczd Oct 18 '16 at 15:01NDSolveshould 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:14DiscreteVariablescan'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