       Re: How to convert a HeavisideTheta to a PieceWise function

• To: mathgroup at smc.vnet.net
• Subject: [mg93797] Re: How to convert a HeavisideTheta to a PieceWise function
• From: Nikolaus Rath <Nikolaus at rath.org>
• Date: Wed, 26 Nov 2008 05:12:23 -0500 (EST)
• References: <gggqf5\$317\$1@smc.vnet.net>

```"wxziwyz at 126.com" <wangxz1983 at gmail.com> writes:
> For example:
> we have f(x) = (x + (-2 + x) HeavisideTheta[-2 + x] -  2 (-1 + x)
> HeavisideTheta[-1 + x]) HeavisideTheta[x]
>
> apparently, this is a piecewise function.
>
> My problem is, How to transfer it into a Piecewise expression, i.e.
>
> f(x) = Piecewise[{{0, x < 0}, {x, 0 < x <= 1}, {2- x, 1 < x <= 2}=
, {0,
> x > 2}}]
>
> Is there any function in Mathematica can do this?

I don't know any such function. But it should be possible to do it
manually. The following seems to work at least for simple cases:

f[x_] := HeavisideTheta[x - 2] x^2 + HeavisideTheta[x + 2] x;
thetas = Extract[f[x], Position[f[x], HeavisideTheta[_]]];
cases = Solve[# == 0, x] & /@ thetas[[All, 1]];
boundaries = (x /. #) & /@ Flatten[cases];
boundaries = {-\[Infinity],
Sequence @@ Sort[boundaries], \[Infinity]};
cases2 = Table[
boundaries[[i]] < x < boundaries[[i + 1]],
{i, Length[boundaries] - 1}]

Piecewise [
{Simplify[f[x], Assumptions -> {#}], #  } & /@ cases2]

It first extracts the arguments of all HeavisideTheta functions. Then
it solves them for x to determine the positions at which the Heaviside
function changes from 0 to 1. It appends -/+ Infinity to this list of
boundaries and constructs a list of cases. Finally, Simplify is used
to get rid of the Heaviside's inside each region.

HTH,

-Nikolaus

--
=C2=BBIt is not worth an intelligent man's time to be in the majority.
By definition, there are already enough people to do that.=C2=AB
-J.H. Hardy

PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

```

• Prev by Date: Re: Mathematica 7.0 slow on OS X
• Next by Date: Re: How to convert a HeavisideTheta to a PieceWise function
• Previous by thread: Re: How to convert a HeavisideTheta to a PieceWise function
• Next by thread: Re: How to convert a HeavisideTheta to a PieceWise function