This is a continuation of my previous post NDSolve returns different answer for different value of xmax
I have managed to resolve the problem of NDSolve returning different answer for different value of xmax
by adding the 4th b.c. D[\[Psi][y, t], t] == 0 /. t -> 0
(refer to How do I use more steps to approximate the boundary condition with NDSolve?).
Here is my code :
ydum = x/L[t];
expr1 = 1/c^2 D[\[Psi][ydum, t], {t, 2}] -
D[\[Psi][ydum, t], {x, 2}] + (m^2 c^2)/
h^2 \[Psi][ydum, t] /. \[Psi][ydum, t] -> \[Psi][y, t] /.
x -> y L[t] // Expand
m = 1;
c = 1;
h = 1;
\[Omega] = 1;
L[t_] := 2 + Sin[\[Omega] t];
sol = NDSolve[{expr1 == 0, \[Psi][0, t] == 0, \[Psi][1, t] ==
0, \[Psi][y, 0] ==
Sqrt[2 (m c)/(c Sqrt[m^2 c^2 + \[Pi]^2 h^2/L[0]^2] L[0])]
Sin[ \[Pi] y], D[\[Psi][y, t], t] == 0 /. t -> 0}, \[Psi], {y,
0, 1}, {t, 0, 10}]
I received a warning from NDSolve :
However, another problem comes up. when I plot
the result :
Manipulate[
Plot[{Abs@Evaluate[\[Psi][y, t]] /. sol}, {y , 0, 3},
PlotRange -> {{0, 3}, {0, 10}}], {t, 0, 10}]
It seems that NDSolve has decided to solve the PDE outside of the range that I have specified {y,0,1}
, and this somehow leads to the solution blowing up at late time (t
). I managed to resolve this by adding DirichletCondition[\[Psi][y, t] == 0, y > 1]
in my NDSolve
:
sol = NDSolve[{expr1 == 0,
DirichletCondition[\[Psi][y, t] == 0, y > 1], \[Psi][1, t] ==
0, \[Psi][0, t] == 0, \[Psi][y, 0] ==
Sqrt[2 (m c)/(c Sqrt[m^2 c^2 + \[Pi]^2 h^2/L[0]^2] L[0])]
Sin[ \[Pi] y], D[\[Psi][y, t], t] == 0 /. t -> 0}, \[Psi], {y,
0, 1}, {t, 0, 10}]
It says that the DirichletCondition
is ignored anyway but this resolves the problem above as can be seen in the plot
To sum up, my question is why does NDSolve evaluate solution outside of the specified range (which I have set to be {y,0,1}
and why does adding DirichletCondition[\[Psi][y, t] == 0, y > 1]
solve the problem when Mathematica says that it ignores it?
Additional Question
I have come across the NeumannValue
for specifying derivative boundary condition. I tried to use this to replace this b.c. D[\[Psi][y, t], t] == 0 /. t -> 0
. Here is my code :
sol = NDSolve[{expr1 == NeumannValue[0, t == 0],
DirichletCondition[\[Psi][y, t] == 0, y > 1], \[Psi][1, t] ==
0, \[Psi][0, t] == 0, \[Psi][y, 0] ==
Sqrt[2 (m c)/(c Sqrt[m^2 c^2 + \[Pi]^2 h^2/L[0]^2] L[0])]
Sin[ \[Pi] y]}, \[Psi], {y, 0, 1}, {t, 0, 10}]
But this doesn't resolve my previous problem (NDSolve returns different answer for different value of xmax). I would like to know what went wrong.