# Wrong values at the boundary of differential equation solution

I have a second order ordinary differential equation and want to solve it numerically. Although I have specified values at the boundary, Mathematica solution does not match with boundary conditions.

h = 10.6
F = 0.001
d = 1.0
L = 100*d
phi[x_] :=
Piecewise[{{0.5*(1 - Tanh[x]),
x < L*0.5/d}, {0.5*(1 + Tanh[x - L/d]), x > L*0.5/d}}]
s = NDSolve[{u''[x] == (h)*phi[x]*phi[x]*u[x] - F*d*d*(1 - phi[x]),
u[-2.5] == 0.0, u[L + 2.5] == 0.0}, u, {x, -2.5, L + 2.5}]
vL[x_] := u[x]/(1 - phi[x])

Plot[Evaluate[{vL[x]} /. s], {x, L/d + 1.5, L/d + 2.5},
PlotRange -> All]

{u[-2.5], u[L + 2.5]} /. s


{{9.02944, -1.11442*10^-25}}


What is the correct way to set the boundary conditions?

-

You can use Method -> "FiniteElement" such as:

h = 10.6;
F = 0.001;
d = 1.0;
L = 100*d;
phi[x_] :=
Piecewise[{{0.5*(1 - Tanh[x]),
x < L*0.5/d}, {0.5*(1 + Tanh[x - L/d]), x > L*0.5/d}}]
s = NDSolveValue[{u''[x] == (h)*phi[x]*phi[x]*u[x] -
F*d*d*(1 - phi[x]), u[-2.5] == 0.0, u[L + 2.5] == 0.0},
u, {x, -2.5, L + 2.5}, Method -> "FiniteElement"]
vL[x_] := u[x]/(1 - phi[x])

Plot[Evaluate[vL[x] /. u -> s], {x, L/d + 1.5, L/d + 2.5},
PlotRange -> All]


-
Thanks user21, When I use this code in Mathematica (version 8.0), it does not produce the plot you have shown, for any plot for that matter. I am not very experienced with Mathematica, do I need something more? – alekhine Aug 26 '14 at 14:46
@alekhine, This uses Version 10. – user21 Aug 26 '14 at 14:51