1
$\begingroup$

Well known and conventional defintion of Heaviside function is

 H(x) = 0,   x < 0 
 H(x) = 1/2, x = 0
 H(x) = 1,   x > 0 

Mathematica uses instead unconventional "unit step" for its $HeavisideTheta[x] $ function

 S(x) = 0,   x < 0 
 S(x) = 1,   x > 0 

How to use in Mathematica proper Heaviside function with normal definiton $H(x)$?

$\endgroup$
1
  • 2
    $\begingroup$ Actually, UnitStep is a separate function, and the link you provided states that HeavisideTheta can be defined in different ways. $\endgroup$ – Jens May 16 '17 at 19:35
2
$\begingroup$
myHeaviside[x_] := Which[x < 0, 0, x == 0, 1/2, x > 0, 1]

Note that the derivative, computed as a limit, is properly a representation of a DiracDelta function (though its integral and higher derivatives might not be appropriately represented):

Limit[(myHeaviside[x + ε] - myHeaviside[x])/ε, ε -> 0]

$\begin{cases} \infty & x=0 \\ 0 & \text{True} \end{cases}$

$\endgroup$
1
  • 3
    $\begingroup$ What do you mean by ``the derivative is properly calculated''? The derivative should yield DiracDelta, I believe. $\endgroup$ – user46676 May 16 '17 at 18:09
7
$\begingroup$

As the link in the question states, you can get the desired definition as follows:

heaviside[x_] := 1/2 (1 + Sign[x])

Here is a test:

heaviside /@ {-1, 0, 1}

{0, 1/2, 1}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.