I want to work with the rectangle function, which I define by
f[x_, m_] := Limit[1/((2*(x - m))^(2*k) + 1), k -> Infinity];
(I know that in theory I can use HeavisidePi[x-m]
to obtain the same function, but using my definition evaluates to 1/2
at the discontinuities, which I want to retain.)
Clearly, the integral of f
with respect to x
over {x, m - 1/2, m + 1/2}
should evaluate to 1
. However, I can't persuade Mathematica to define the integral at all: the code
Clear["Global`*"];
f[x_, m_] := Limit[1/((2*(x - m))^(2*k) + 1), k -> Infinity];
Module[{m = 0}, Plot[f[x, m], {x, -1, 1}, GridLines -> Automatic]]
Module[{m = 0}, Integrate[f[x, m], {x, m - 1/2, m + 1/2}]]
yields the desired plot, but returns Undefined
for the integral.
I have tried adding Assumptions
but clearly not the right ones, because it doesn't work. I have tried using NIntegrate
, but it doesn't work. I have tried changing the definition of f
to HeavisidePi[x-m]
(which I don't want to do anyway), but it doesn't work. I have tried using a Piecewise
definition - same non-result...
How do I obtain the correct result?
f[x, 0]
evaluate correctly? $\endgroup$ConditionalExpression[0, Log[2 x] > 0]
. It's not clear to me whatIntegrate
will be able to do with it. I will suggest that if you want a Heaviside function but with a value at the origin, create it withPiecewise
. $\endgroup$HeavisidePi
? It keepsHeavisidePi[1/2]
andHeavisidePi[-1/2]
unevaluated. If some of your outputs containHeavisidePi[1/2]
you can simply replace it with desired value - likeHeavisidePi[1/2]->1/2
orHeavisidePi[-1/2]->1/2
. $\endgroup$f[0,0]
evaluates correctly to1
; (2) @Daniel, I'm not sure I understand the reservation: at least until the limit->Infinity
is reached,f
is an entire (and therefore integrable) function - and in the limit the definite integral described clearly produces1
(having said this, I did tryPiecewise
but that didn't work either, any least with the half-values at the discontinuities); (3) As mentioned in the OP,HeavisidePi
also produces anUndefined
result under integration. $\endgroup$Undefined
?Integrate[HeavisidePi[x - m], {x, m - 1/2, m + 1/2}] /. m -> 0
nicely evaluates into1
. $\endgroup$