# PDE solution does not satisfy Neumann boundary conditions using NDSolve

I am trying to solve the free particle Schrodinger equation in 1D (hbar =1, Energy = 1, mass = 1), But specifying conditions only on x==0:

k = Sqrt[2];
sol = NDSolveValue[{op == NeumannValue[0, x == 0],
DirichletCondition[u[x] == Cos[k x], x == 0]}, u, {x, 0, 1}]

Plot[{sol[x] , Cos[k x]}, {x, 0, 1}]


The blue line is the numeric solution, and it is obviously not the expected solution (in orange), since the derivative in x==0 is not zero. I understand that specifying the Neumann value is not needed since its default is zero, but it isn't zero here!

What is going on?

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– user9660
Commented Feb 26, 2015 at 13:35

Both NeumannValue and DirichletCondition are set to apply at x==0. In such cases the DirichletCondition will trump the NeumannValue. Besides the NeumannValue is set to zero which means that the natural boundary condition is 0, the boundary integral vanishes. I think you want the DirichletCondition at x==1:

k = Sqrt[2];
sol = NDSolveValue[{op == NeumannValue[0, x == 0],
DirichletCondition[u[x] == Cos[k x], x == 1]}, u, {x, 0, 1}];


But NeumannValue[0,...] is equivalent to not specifying anything at all:

k = Sqrt[2];
sol = NDSolveValue[{op == 0,
DirichletCondition[u[x] == Cos[k x], x == 1]}, u, {x, 0, 1}];

Plot[{sol[x] - Cos[k x]}, {x, 0, 1}]


• I am actually interested in solving using conditions only at x == 0. I want to use DiriclehtCondition and NeumannValue to get the equivalent solution to this: NDSolveValue[{-1/2 u''[x] - u[x] == 0, u[0] == Cos[k 0] , u'[0] == -k Sin [k 0]}, u, {x, 0, 1}] Is it not possible? Commented Feb 26, 2015 at 16:24
• @AmitAbir, no, that's not possible. Why do you have that restriction? Commented Feb 26, 2015 at 16:53
• @AmitAbir, note that the above NDSolve does a time integration, while the FEM is a spatial discretization method. Commented Feb 26, 2015 at 18:17
• Well, eventually I wish to solve this problem in 3 dimensions. In my problem there are two concentric spheres and I wish to solve Schrodinger's equation in the region between the spheres. The problem is I have boundary condition only on the inner sphere (Both Dirichlet and Neumann). Is it not solvable? Is it not possible to specify both Neumann and Dirichlet condition on the same part of the boundary? Is there any other method to solve this other then FEM? Commented Feb 27, 2015 at 7:54
• @AmitAbir, if one does not specify boundary conditions on the outer sphere that implies that a Neumann zero boundary condition is used; it's not possible to have both Dirichlet and Neumann conditions at the same position. Is it generally not solvable, that I do not know. Commented Feb 27, 2015 at 10:24