1
$\begingroup$

HeavisideTheta function always gives 0 or 1. I wonder if this is possible to define my own value for the HeavisideTheta function other than 0 and 1, say 0.5, only for a specific notebook. Also, how to remove that specific value whenever I want and return its default value 0 or 1. Thanks!

Example:

For the following function,

HeavidsideTheta[0.5-x]

I want

HeavidsideTheta[0.5-x] = 1 when x < 0.5

and

HeavidsideTheta[0.5-x] = 1 when x >= 0.5

Note: This function is a part of other functions of "x" where integrals are involved.

$\endgroup$
2
  • 6
    $\begingroup$ This may be obvious but you can multiply it by any number or function you like to give what you need. You could write a function f[x_]:= 0.5 HeavisideTheta[x] $\endgroup$
    – Hugh
    Commented Mar 3, 2022 at 11:53
  • $\begingroup$ Please see above example $\endgroup$
    – SciJewel
    Commented Mar 3, 2022 at 13:04

3 Answers 3

4
$\begingroup$

Try:

moh[x__] := (1/2)*HeavisideTheta @@ {x}

Regarding your example, just reverse the sign, multiply the 'amplitude' and add the minimum:

moh[x__] := 1/2 + (1/2)*HeavisideTheta @@ {-x}
Plot[{moh[t - 1/2]}, {t, 0, 1}, PlotRange -> {0, 1}]

enter image description here

You can achieve the same thing by simply adding various step functions: (1/2)*UnitStep[t - 1/2] + UnitStep[-(t - 1/2)].

$\endgroup$
4
  • $\begingroup$ Please see the above example $\endgroup$
    – SciJewel
    Commented Mar 3, 2022 at 13:04
  • $\begingroup$ The line corresponding to -1 should correspond to 1 and the other should 0.5. I don't need the -1 part. Only 1 and 0.5 is required. $\endgroup$
    – SciJewel
    Commented Mar 3, 2022 at 13:32
  • $\begingroup$ sorry, the first line to 1 and 2nd to 0.5 $\endgroup$
    – SciJewel
    Commented Mar 3, 2022 at 13:42
  • $\begingroup$ Now it worked. Thanks, Shin Kim!! $\endgroup$
    – SciJewel
    Commented Mar 3, 2022 at 14:21
3
$\begingroup$
a = .5;
b = 3;
c = 2;
Plot[a + (b - a)*HeavisideTheta[x - c], {x, -5, 8}, 
 AxesOrigin -> {0, 0}]

enter image description here

$\endgroup$
2
$\begingroup$

Using the Clip command, I show two variations using the 2nd and 3rd argument of the function:

Plot[{
  Clip[HeavisideTheta[0.5 - x], {0.3, 0.8}]
  , Clip[HeavisideTheta[0.5 - x], {0.3, 0.8}, {2, 4}]
  }
 , {x, -2, 2}
 , PlotRange -> {-0.2, 4.2}
 , Exclusions -> None
 ]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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