2
$\begingroup$

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 : enter image description here

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}]

enter image description here

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}]

enter image description here

It says that the DirichletCondition is ignored anyway but this resolves the problem above as can be seen in the plot enter image description here

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.

$\endgroup$

1 Answer 1

4
$\begingroup$

NDSolve does not compute the solution outside of the domain. However, the interpolating function NDSolve returns can be evaluated outside of the solution domain. In those cases it extrapolates the solution outside the domain. Now, why does adding a DirichletConditon change that. Well, when you add a DirichletCondition you (implicitly) force the solution method to be the finite element method. For the finite element method the possibility of extrapolation of the result is switched off. This is done because in case of the finite element method we know nothing beyond the domain. In the FEM case, the boundary conditions are all we know at the boundary.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.