Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

UnitStep vs Piecewise

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112659] UnitStep vs Piecewise
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sat, 25 Sep 2010 02:19:52 -0400 (EDT)

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.

 

 

David Park

djmpark at comcast.net

 <http://home.comcast.net/~djmpark> http://home.comcast.net/~djmpark/  

 


  • Prev by Date: Re: Creating a Grid with square cells
  • Next by Date: Re: ContourPlot under ListPlot3D
  • Previous by thread: Re: calculate vertex of a parabola
  • Next by thread: Re: UnitStep vs Piecewise