I am trying to model/solve a specific instance of a 1D diffusion equation in which I have a nonlinear Neumann boundary condition at x=1 (length of unit 1). My equations that I have are:

D[u[x,t],t] == D[u[x,t], x, x] for the general diffusion equation;

D[u[1,t],x] == 10 - Log[u[1, t]+1] for a flux at boundary x=1 that begins at 10 and decreases as a function of Log of concentration at the boundary;

D[u[0,t],x] == 0 for a no flux boundary at x=0;

u[x,0] == 0 for an initial concentration of 0 everywhere in the rod.

What I am trying to see occur is a function where the heat spreads across the rod and smoothes out across the rod to a steady-state/equilibrium; additionally, the goal is to have the flux approach zero and remain at zero (which represents the difference in chemical potentials between the domain and an external source approaching zero).

Upon further reconsideration, I was able to use NDSolve to find a plot that looks somewhat like what my goal is. However, I want the diffusion to continue across the domain until it smoothes out. Here is my code:


This gives a decent solution as said but results in two errors.

NDSolve: Warning: boundary and initial conditions are inconsistent.
NDSolve: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable x. Artificial boundary effects may be present in the solution.

My three questions are as follows:

  1. Should I address this warnings if it still gives a close enough solution?
  2. How do I get a curve where the concentration smoothes out over the domain (and as time moves forward)?
  3. Is there a way to get a 2D list line plot that shows the curves as lines where each line represents a different time?

Sorry if that is too much to ask. If you can help tackle any of these questions, that will be greatly appreciated. Thank you!

enter image description here

  • 1
    $\begingroup$ Note : your code call (automatically) the TensorProductGrid method, as opposed to the FiniteElement method. I have unsuccessfully tried the finite element method (NDSolve[{D[c[x, t], t] == D[c[x, t], x, x],D[c[1, t], x] == 10 - Log[c[1, t] + 1], c[x, 0] == 0}, c, {t, 0, 10}, {x, 0, 1}, Method -> "FiniteElement"] ) which doesn' t work in this case . The error message is explicit : "The dependent variable in the boundary condition needs to be linear." $\endgroup$
    – andre314
    Jul 4, 2021 at 20:26
  • $\begingroup$ @andre314 How would one go about fixing this? I want the dependent variable in the boundary to be non-linear purposely for my model. Is there anything that I can do to fix it to work with the Log? $\endgroup$ Jul 4, 2021 at 20:41
  • 1
    $\begingroup$ I don't know. The aim of my comment was only to avoid that you spend much time to try the finite element method in this case. Concerning the TensorProductGrid method, I can't say if it can work. $\endgroup$
    – andre314
    Jul 4, 2021 at 21:14
  • 1
    $\begingroup$ 1. D[c[1,t],x] is wrong. One possible correction is D[c[x, t], x]/. x->1. 2. The bcart warning is a serious problem. See this post for more info: mathematica.stackexchange.com/q/73961/1871 Notice you've forgotten the b.c. D[u[x,t],x]==0/.x->0. 3. The ibcinc warning is a serious problem in this case, you need Method->{"MethodOfLines","DifferentiateBoundaryConditions"->{True,"ScaleFactor"->100}}, check this post for more info: mathematica.stackexchange.com/a/127411/1871 $\endgroup$
    – xzczd
    Jul 5, 2021 at 2:04

1 Answer 1


We can solve this problem by introducing damping factor to make bc and ic are consistent as follows

 sol = NDSolve[{D[c[x, t], t] == D[c[x, t], x, x], 
   Derivative[1, 0][c][1, 
      t] - (10 - Log[c[1, t] + 1]) (1 - Exp[-5 t]) == 0, 
   Derivative[1, 0][c][0, t] == 0 /. x -> 0, c[x, 0] == 0}, 
  c, {t, 0, 10}, {x, 0, 1}]

Plot3D[c[x, t] /. sol[[1]], {x, 0, 1}, {t, 0, 10}, Mesh -> None, 
 ColorFunction -> "Rainbow", AxesLabel -> Automatic, 
 PlotTheme -> "Marketing"] 

Figure 1


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.