MathGroup Archive 2010

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

Search the Archive

Re: UnitStep vs Piecewise

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112684] Re: UnitStep vs Piecewise
  • From: Joseph Gwinn <joegwinn at comcast.net>
  • Date: Sun, 26 Sep 2010 02:45:18 -0400 (EDT)
  • References: <i7k4b6$lf4$1@smc.vnet.net>

In article <i7k4b6$lf4$1 at smc.vnet.net>,
 "David Park" <djmpark 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 properly.
> 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.

My suspicion would be that Piecewise But cannot handle infinite slopes, 
such as those at the edges of the pulse.  Piecewise ought to be able to 
handle a pulse with finite rise and fall times, being a trapezoid versus 
a rectangle.

Joe Gwinn


  • Prev by Date: PSE Example 8.6 via Reduce
  • Next by Date: Perhaps a FindMinimum issue...
  • Previous by thread: UnitStep vs Piecewise
  • Next by thread: Re: UnitStep vs Piecewise