MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NDSolve and Piecewise

On Sep 18, 11:57 pm, "M.G. Bartlett" <marshall.bartl... at>
> Folks,
> 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, =
> {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
> around somewhere it ought not to be.  I can't see any such problem
> this time.  I'm pretty sure that I have written similar code in the
> past (using Piecewise and NDSolve, though it was some time ago and I
> can't locate the file now) and had it work, and it works if you
> replace Piecewise with another functional form (like Sin[t]).  Am I
> missing something?
> Thanks,
> Marshall

Thanks to those of you who replied and indicated (as I discovered
shortly after posting) that the error is associated with the piecewise
function not having a well-defined derivative at the boundaries (t=0
and t=10, in the example above).  A couple of you indicated that this
can be remedied by extending the piecewise function across the model
domain boundaries (i.e., replace the condition 0 <= t < 5 with t < 5
and likewise for the boundary at the other end of the time domain).
This "fix" does the trick.

I guess I just figured that Mathematica would be able to tell that it
should approach the derivative at the boundary from only a single
side.  I get so use to having the program see a problem the same way
that I do that it can be surprising when it behaves differently
(though, as in this case, Mathematica is of course technically correct
to complain).

Thanks again to all those who responded.



  • Prev by Date: Re: Debracketing array symbols
  • Next by Date: Re: the graphic of a function
  • Previous by thread: Re: NDSolve and Piecewise
  • Next by thread: Column/Row/Grid bars FrontEnd String formatting in new cells?