Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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];
op = Inactivate[Div[{{-0.5}}.Grad[u[x], {x}], {x}], Div | Grad] - u[x];
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}]

enter image description here

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?

share|improve this question
    
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! –  Lou Feb 26 at 13:35

1 Answer 1

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];
op = Inactivate[Div[{{-0.5}}.Grad[u[x], {x}], {x}], Div | Grad] - u[x];
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];
op = Inactivate[Div[{{-0.5}}.Grad[u[x], {x}], {x}], Div | Grad] - u[x];
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}]

enter image description here

share|improve this answer
    
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? –  Amit Abir Feb 26 at 16:24
    
@AmitAbir, no, that's not possible. Why do you have that restriction? –  user21 Feb 26 at 16:53
    
@AmitAbir, note that the above NDSolve does a time integration, while the FEM is a spatial discretization method. –  user21 Feb 26 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? –  Amit Abir Feb 27 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. –  user21 Feb 27 at 10:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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