5
$\begingroup$

I tried to solve a simple ODE with only Neumann conditions like enter image description here But obviously this doesn't work. I must add a useless DirichletCondition to make it work enter image description here I have verified that the solution is correct, but how can I get it without including the useless condition?

The code is

Sol = NDSolveValue[{Piecewise[{{1, x < 0}, {2.25, x > 0}}, 0]*u[x] + 
 Derivative[2][u][x] == 
     NeumannValue[I*(2*E^(I*x) - u[x]), x == -4*Pi] + 
 NeumannValue[(0. - 1.5*I)*u[x], x == 4*Pi], 
   DirichletCondition[1, False]}, u, {x, -4*Pi, 4*Pi}]
ReImPlot[Sol[x], {x, -4*Pi, 4*Pi}]
$\endgroup$
4
  • 2
    $\begingroup$ With only Neumann conditions, the solution is determined only up to a constant. one way or another, the constant must be specified to obtain a numerical solution. $\endgroup$
    – bbgodfrey
    Feb 16 '20 at 4:51
  • $\begingroup$ Maybe not, because if I add some useless condition like DirichletCondition[1, False], the program would find the correct solution. $\endgroup$ Feb 16 '20 at 11:21
  • $\begingroup$ @ZhuoJiahui I received this message in version 12 NDSolveValue::fembpw: The boundary condition {DirichletCondition[1,False]} cannot be parsed and will be ignored. $\endgroup$ Feb 16 '20 at 12:21
  • $\begingroup$ Yeee, that condition will be ignored but the solution is correct. $\endgroup$ Feb 16 '20 at 14:01
4
$\begingroup$

You'd need to specify the method in this case, as otherwise NDSolve will first try to solve this as a time ODE:

Sol = NDSolveValue[{Piecewise[{{1, x < 0}, {2.25, x > 0}}, 0]*u[x] + 
     Derivative[2][u][x] == 
    NeumannValue[I*(2*E^(I*x) - u[x]), x == -4*Pi] + 
     NeumannValue[(0. - 1.5*I)*u[x], x == 4*Pi]}, u, {x, -4*Pi, 4*Pi},
   Method -> "FiniteElement"]

The fact that you 'only' have NeuamnnValues is not a problem here as they are generalized Neumann conditions (Robin conditions). Using only NeumannValue is only an issue if the NeumannValue is not a generalized NeumannValue (i.e. does not dependend on the dependent variable u in this case)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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