Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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

share|improve this answer
    
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 at 14:46
    
@alekhine, This uses Version 10. –  user21 Aug 26 at 14:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.