I'm interesting in solving this problem where I have a Dirichlet boundary condition at $\ x=0, u(x)=1$ and a Neumann boundary condition where at $\ x=25, du/dx=0$

I was able to get it to work when having 2 Dirichlet boundary conditions $\ x=0, u(x)=1$ and $\ x=25, u(x)=0$ and wanted to compare if I would get a similar answer if I applied a Neumann boundary condition instead. I was also interested in comparing both answers with DSolve and NDSolve.

Here is my code. Am I setting up the NeumannValue function incorrectly?


k = 0.25;
diffCo = 1*10^-6;

bc1 = DirichletCondition[u[x] == 1, x == 0];
bc2 = NeumannValue[0, x == 25];

eqn = diffCo*u''[x] - k*u[x] == 0;

solDSolve = u[x] /. First@DSolve[{eqn, bc1, bc2}, u[x], {x, 0, 25}]

solNDSolve = 
 NDSolve[{eqn, bc}, u, {x, 0, 25}, 
  Method -> {"FiniteElement", MeshOptions -> MaxCellMeasure -> 0.001}]

I get the error

DSolve::deqn: Equation or list of equations expected instead of NeumannValue[0.,x==25] in the first argument {-0.25 u[x]+(u^\[Prime]\[Prime])[x]/1000000==0,{u[0]==1},NeumannValue[0.,x==25]}.


NDSolve::deqn: Equation or list of equations expected instead of bc in the first argument {-0.25 u[x]+(u^\[Prime]\[Prime])[x]/1000000==0,bc}.

Any help is greatly appreciated. Thank you!

  • 2
    $\begingroup$ NeumannValue has to be a part of equation eqn. See similar examples in documentation for this symbol. $\endgroup$ – Pinti Jun 6 '18 at 7:29
  • 2
    $\begingroup$ And zero NeumannValue doesn't need to be set actually. It's the default value. $\endgroup$ – xzczd Jun 6 '18 at 7:58
  • $\begingroup$ @Pinti @xzczd Ohhh. I completely missed that when looking at the examples. Thank you! Although, now I'm getting an error saying RowReduce::luc: Result for RowReduce of badly conditioned matrix {{1.,1.,-1.},{-1.042188348916432*10^-5426,2.398798645752719*10^5431,0.}} may contain significant numerical errors. What is causing this and how do I to resove this? $\endgroup$ – AhWee Jun 6 '18 at 21:31