Re: UnitStep vs Piecewise
- To: mathgroup at smc.vnet.net
- Subject: [mg112676] Re: UnitStep vs Piecewise
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Sun, 26 Sep 2010 02:43:48 -0400 (EDT)
- References: <i7k4b6$lf4$1@smc.vnet.net>
David,
If you define g as a definite integral it works out OK.
g[value_, t1_, t2_][t_] =
Integrate[f[value, t1, t2][tx], {tx, -\[Infinity], t}]
Using the indefinite integral wouldn't be correct in general, would
it? It works here because you start at zero, but otherwise, it would
be wrong.
Cheers -- Sjoerd
On Sep 25, 8:20 am, "David Park" <djmp... at comcast.net> wrote:
> It appears to me that there is a bug in Piecewise when it is used inside an
> Integrate or DSolve expression. On the other hand UnitStep behaves proper ly.
> Here is the example.
>
> I'm defining a square pulse using symbolic values for the start and stop
> times and then integrating it. Using UnitStep:
>
> Clear[f, g];
>
> f[value_, t1_, t2_][t_] := value (UnitStep[t - t1] - UnitStep[t - t2])
>
> g[value_, t1_, t2_][t_] = Integrate[f[value, t1, t2][t], t]
>
> Alternatively, we could calculate g by using DSolve.
>
> deqns = {g'[t] == f[value, t1, t2][t], g[t1] == 0};
>
> gsol = DSolve[deqns, g, t][[1]];
>
> g[value_, t1_, t2_][t_] = g[t] /. gsol
>
> Plot[{f[1, 0, 1][t], g[1, 0, 1][t]}, {t, -1, 2},
>
> Exclusions -> None,
>
> PlotStyle -> {Thin, Thick},
>
> PlotRangePadding -> {0, 0.2},
>
> Frame -> True, Axes -> False]
>
> Using Piecewise there appears to be a bug:
>
> Clear[f, g];
>
> f[value_, t1_, t2_][t_] := Piecewise[{{value, t1 < t < t2}}]
>
> g[value_, t1_, t2_][t_] = Integrate[f[value, t1, t2][t], t]
>
> Or alternatively using DSolve:
>
> deqns = {g'[t] == f[value, t1, t2][t], g[t1] == 0};
>
> gsol = DSolve[deqns, g, t][[1]];
>
> g[value_, t1_, t2_][t_] = g[t] /. gsol
>
> Plot[{f[1, 0, 1][t], g[1, 0, 1][t]}, {t, -1, 2},
>
> Exclusions -> None,
>
> PlotStyle -> {Thin, Thick},
>
> PlotRangePadding -> {0, 0.2},
>
> Frame -> True, Axes -> False]
>
> Just in case I don't know how to use Piecewise, I also tried starting with
> the UnitStep definition and then converting to Piecewise using
> PiecewiseExpand, but that lead to the same error. The problem with Piecewise
> occurs with symbolic values t1 and t2 and not if it is defined with
> numerical values. I was under the impression that Piecewise was a more
> general method than using UnitStep, but perhaps not.
>
> David Park
>
> djmp... at comcast.net
>
> <http://home.comcast.net/~djmpark>http://home.comcast.net/~djmpark/