Re: NDSolve and Piecewise
- To: mathgroup at smc.vnet.net
- Subject: [mg92111] Re: NDSolve and Piecewise
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sat, 20 Sep 2008 04:59:45 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <gavt1g$g61$1@smc.vnet.net>
M.G. Bartlett wrote:
> I am having some trouble with getting Piecewise and NDSolve to play
> nicely together. My problem is to find a solution to the heat flow
> equation with an arbitrary time-varying upper boundary condition and a
> Neumann-type lower boundary (steady head flow condition). My code
> looks like this:
>
> NDSolve[{D[u[t, x], t] == D[u[t, x], x, x],
> u[t, 0] == Piecewise[{{t/10, 0 <= t < 5}, {(10 - t)/10, 5 <= t <
> 10}}],
> u[0, x] == x/5, (D[u[t, x], x] /. x -> 5) == 1/5}, u, {t, 0, 10},
> {x, 0, 5}]
>
> This returns and NDSolve::ndum error on my system, which past
> experience tells me is usually me leaving some symbolic value hanging
*snip*
The issue might arise from your piecewise function, which is not smooth
enough: its first derivative does not exist at t == 0, 5, and 10 (kinks)
(Mathematica returns Indeterminate for this cases, see below).
In[1]:=
f[t_] := Piecewise[{{t/10, 0 <= t < 5}, {(10 - t)/10, 5 <= t < 10}}, 0]
f'[t]
Plot[f[t], {t, -15, 15}]
Out[2]=
1 1
Piecewise[{{0, t < 0}, {--, 0 < t < 5}, {-(--), 5 < t < 10},
10 10
{0, t > 10}}, Indeterminate]
Out[3]= [... triangle shape graph deleted ...]
Regards,
-- Jean-Marc