7
$\begingroup$

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

Mathematica graphics

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

What is the correct way to set the boundary conditions?

$\endgroup$

1 Answer 1

6
$\begingroup$

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]

enter image description here

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – alekhine
    Commented Aug 26, 2014 at 14:46
  • $\begingroup$ @alekhine, This uses Version 10. $\endgroup$
    – user21
    Commented Aug 26, 2014 at 14:51

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.