# NDSolve solution is non sequential to be used in replace

I have a differential equation and I need to obtain the solution and evaluate it just after. The reason for this is that I need to give the values x, u and t as parameters, which I think should be done in a module. Somehow when I evaluate, I get the error "ReplaceAll::reps: {sol} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing." This only happens the first time I run it, if I run it a second time, it is like mathematica realizes that the solution does exist and lets me use it as replace just fine. This is my specific problem with some parameters:

σA = 0.2;
σX = 0.4;
sD = 0.13;
sS = 0.2;
ϕ = 95/100;
gA = (σX^2 (σX^2 (1 - ϕ) + \
σA^2))/(σX^2 + σA^2);
gB = (σX^2 σA^2)/(σX^2 + σA^2);
γA1[t_] := 1/(  t (1/sD^2 + ϕ^2/sS^2) + 1/gA);
γB1[t_] := sD^2/ (t + sD^2/gB);
PDEC = - 2 HC[
p] (γB1[-p + u]/sD^2 - (
x (γB1[-p + u] - γA1[-p + u]) )/sD^2) + ( (
x (x - 1))/(2 sD^2)) +
2 HC[p]^2 ((γB1[-p + u] - γA1[-p + u])^2/
sD^2 + (ϕ^2 (γA1[-p + u])^2)/sS^2) -
Derivative[HC][p];
x = 1/3; u = 25; t = 0.1; sol =
NDSolve[{PDEC == 0, HC == 0},
HC, {p, Re[(u - t) - 0.1], Re[(u - t) + 0.1]}]; Evaluate[
HC[25 - 0.1] /. sol]

• Your code runs perfectly fine on my computer. Try running in a fresh kernel. Jun 14, 2017 at 13:30

When Mathematica digests the code block, it see the Evaluate and tries to act on it immediately. This also means it would use the value of sol from the previous time you ran the block, which may not be your intent. Just get rid of Evaluate from the next to last line.

σA = 0.2;
σX = 0.4;
sD = 0.13;
sS = 0.2;
ϕ = 95/100;
gA = (σX^2 (σX^2 (1 - ϕ) + \
σA^2))/(σX^2 + σA^2);
gB = (σX^2 σA^2)/(σX^2 + σA^2);
γA1[t_] := 1/(  t (1/sD^2 + ϕ^2/sS^2) + 1/gA);
γB1[t_] := sD^2/ (t + sD^2/gB);
PDEC = - 2 HC[
p] (γB1[-p + u]/sD^2 - (
x (γB1[-p + u] - γA1[-p + u]) )/sD^2) + ( (
x (x - 1))/(2 sD^2)) +
2 HC[p]^2 ((γB1[-p + u] - γA1[-p + u])^2/
sD^2 + (ϕ^2 (γA1[-p + u])^2)/sS^2) -
Derivative[HC][p];
x = 1/3; u = 25; t = 0.1; sol =
NDSolve[{PDEC == 0, HC == 0},
HC, {p, Re[(u - t) - 0.1], Re[(u - t) + 0.1]}];

(* Take out the Evaluate[ ] *)
HC[25 - 0.1] /. sol

    \[Sigma]A = 0.2;
\[Sigma]X = 0.4;
sD = 0.13;
sS = 0.2;
\[Phi] = 95/100;
gA = (\[Sigma]X^2 (\[Sigma]X^2 (1 - \[Phi]) + \
\[Sigma]A^2))/(\[Sigma]X^2 + \[Sigma]A^2);
gB = (\[Sigma]X^2 \[Sigma]A^2)/(\[Sigma]X^2 + \[Sigma]A^2);
\[Gamma]A1[t_] := 1/(t (1/sD^2 + \[Phi]^2/sS^2) + 1/gA);
\[Gamma]B1[t_] := sD^2/(t + sD^2/gB);
PDEC = {-2 HC[
p] (\[Gamma]B1[-p + u]/
sD^2 - (x (\[Gamma]B1[-p + u] - \[Gamma]A1[-p + u]))/
sD^2) + ((x (x - 1))/(2 sD^2)) +
2 HC[p]^2 ((\[Gamma]B1[-p + u] - \[Gamma]A1[-p + u])^2/
sD^2 + (\[Phi]^2 (\[Gamma]A1[-p + u])^2)/sS^2) -
Derivative[HC][p] == 0};

x = 1/3; u = 25; t = 0.1;
sol = NDSolve[{PDEC, HC == 0},
HC[p], {p, Re[(u - t) - 0.1], Re[(u - t) + 0.1]}];

Plot[Evaluate[First[HC[p] /. %]], {p, 0, 20}]
Evaluate[First[HC[p] /. sol]] /. p -> (25 - 0.1)