[Date Index]
[Thread Index]
[Author Index]
Re: NDSolve and Piecewise
*To*: mathgroup at smc.vnet.net
*Subject*: [mg92106] Re: NDSolve and Piecewise
*From*: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
*Date*: Sat, 20 Sep 2008 04:58:49 -0400 (EDT)
*Organization*: University System of Maryland
*References*: <gavt1g$g61$1@smc.vnet.net>
Marshall,
I am sure others will have a better way, but I use
(1+Tanh[alpha(t-t0)])/2 to generate a "step" in which the sharpness of
the step is determined by alpha. The advantage is that it is
differentiable. Here is some code to redefine you u[t,0] condition:
Clear[g, step]
step[\[Alpha]_, t_,t0_] := (1 + Tanh[\[Alpha] (t - t0)])/2
g[t_] := t/10 (1 - step[7, t,5]) + (10 - t)/10 step[7, t,5]
When I used u[t,0]==g[t] in your code, it worked. (I plotted u and it
looks "reasonable".) I set alpha =7 for no very good reason. You could
do otherwise.
Kevin
M.G. Bartlett wrote:
> 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, 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
> 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
>
Prev by Date:
**Re: Functional programming?**
Next by Date:
**Re: NDSolve and Piecewise**
Previous by thread:
**Re: NDSolve and Piecewise**
Next by thread:
**Re: NDSolve and Piecewise**
| |