# Evaluation to true using DSolve - syntax errors?

Probably a stupid question, apologies, but I am getting an annoying error when I try to evaluate the following simple PDE

$\frac{\partial C}{\partial t} = d \frac{\partial^2C}{\partial x^2}$ between $0$ and $L$ when $\frac{\partial C}{\partial x}(0,t) = \frac{\partial C}{\partial x}(L,t) = 0$ and $C(x,0) = 10e^{-k(L-x)}$. I've tried the following but keep getting an error about my first boundary condition evaluating to true. There must be something wrong with how I've written it, but I am driven demented trying to find it. Can anyone clear up where I've messed up?

DSolve[{D[C[x, t], t] - d*D[C[x, t], {x, 2}] == 0,
D[C[x, t], x] /. x -> 0 == 0 , D[C[x, t], x] /. x -> L == 0 ,
C[x, 0] == 10 Exp[-k*(L - x)]}, C[x, t], {x, t}]

• Move the replacements to the end of the equations, i.e. change /. x -> L == 0 to == 0/. x -> L. Also C is a reserved symbol in Mathematica; use c. In general, you should use lower-case letters for user-defined symbols, because all Mathematica functions begin with capital letters. The reason this is a problem is that == binds "harder" than /.. Meditate on the outputs after evaluating the following two expressions: b a == b /. a -> 1 and b a /. a -> 1 == b. – march Oct 15 '15 at 15:51
• At least in V9 the docs state: "The heat equation is parabolic, but it is not considered here because it has a nonvanishing non-principal part, and the algorithm used by DSolve is not applicable in this case." – Dr. belisarius Oct 15 '15 at 15:56
• @belisariusisforth. Yes: once the syntax issues are fixed, DSolve returns unevaluated in V10. WHere did you find that in the documentation? I'm looking to see if it's the same in V10. – march Oct 15 '15 at 15:58
• @march Last sentence here reference.wolfram.com/mathematica/tutorial/… – Dr. belisarius Oct 15 '15 at 16:00
• @belisariusisforth. Yeah, that's still there in my V10 documentation. – march Oct 15 '15 at 16:02

I think this is worth an answer, since it has to do with the subtleties of precedence of Infix operators. Consider the following two evaluations:

b a == b /. a -> 1
b a /. a -> 1 == b
(* True *)
(* b (1 == b) *)


The reason these outputs are different is that == binds "harder" (there's correct terminology that I'm missing here) than /.. The FullForm of these expressions looks like this:

Hold[b a == b /. a -> 1] // FullForm
Hold[b a /. a -> 1 == b] // FullForm
(* Hold[
ReplaceAll[Equal[Times[b, a], b], Rule[a, 1]]
] *)
(* Hold[
ReplaceAll[Times[b,a],Rule[a,Equal[1,b]]]
] *)


Simplifying a bit, this means that in the first case, you are replacing a for 1 in the expression

b a == b


which turns it into b == b, which evaluates to True. In the second case, you are replacing a with b == 1 in the expression

b a


which evaluates to b*(1 == b).

So, in your case, for instance, when you do

D[c[x, t], x] /. x -> 0 == 0


The last part of the expression is interpreted on its own as Equal[0, 0] (or 0 == 0), which evaluates to True. After that evaluation, x gets replaced by True in the expression D[c[x, t], x], so that you get

D[c[True, t], True]


which then is shown as

Derivative[1,0][c][True,t]


Just for fun, let's see why no error is thrown:

D[True^2, True]
(* 2*True *)


D has no problem thinking of True as a variable and taking a derivative with respect to it. These won't work however:

D[a + 1, 1]
D[a + b, a + b]

• Cheers for this! Seems PDE not solvable by DSolve, alas... – DRG Oct 15 '15 at 16:20
• @DRG. Yep. Do it numerically! – march Oct 15 '15 at 16:22

The just released version of DSolve is more powerful than the old. With

\$Version
(* "10.3.0 for Microsoft Windows (64-bit) (October 9, 2015)" *)


it now produces a solution.

DSolve[{D[C[x, t], t] - d*D[C[x, t], {x, 2}] == 0, (D[C[x, t], x] /. x -> 0) == 0,
(D[C[x, t], x] /. x -> L) == 0, C[x, 0] == 10 Exp[-k*(L - x)]}, C[x, t], {x, t}][[1, 1]]

(* C[x, t] -> (10 - 10/E^(k*L))/(k*L) +
(2*Inactive[Sum][(10*E^(-(k*L) - (d*Pi^2*t*K^2)/L^2)*
(-1 + (-1)^K*E^(k*L))*k*L^2*Cos[(Pi*x*K)/L])/
(k^2*L^2 + Pi^2*K^2), {K, 1, Infinity}])/L *)


Note that Sum is Inactive. Activating it causes Mathematica to attempt to do the sum explicitly, and it still is trying on my computer. Nonetheless, I think that this formal solution is quite useful.