MathGroup Archive 2011

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

Search the Archive

Re: Even and Odd functions

  • To: mathgroup at
  • Subject: [mg119379] Re: Even and Odd functions
  • From: Bill Rowe <readnews at>
  • Date: Wed, 1 Jun 2011 04:33:37 -0400 (EDT)

On 5/31/11 at 7:48 AM, yitzhakbg at (yitzhakbg) wrote:

>Applying makeper makes the piecewise functions x and y periodic, yet
>they don't appear as even and odd functions whereas the Sin and Cos
>functions do show as odd and even. xx and yy are the functions which
>fail the even/odd test yet show as even and odd according to the
>plots. I couldn't determine why. Help appreciated.

>ClearAll[x, y, xx, yy, makeper]

>x[t_] := Piecewise[{{-1, -1/2 <= t < 0}, {1, 0 <= t < 1/2}}]
>y[t_] := Piecewise[{{-t - 1/4, -1/2 <= t < 0}, {t - 1/4, 0 <= t < 1/2}}]

>makeper[f_, p_, d_][t_] := f[Mod[t, p, d]]
>(* Plot[x@t,{t,-5,5},PlotRange->{-1,1}] *)

>xx[t_] := makeper[x, 1, -1/2]@t
>yy[t_] := makeper[y, 1, -1/2]@t
>Plot[xx[t], {t, -5, 5}, PlotRange -> {-1, 1}]
>Plot[yy[t], {t, -5, 5}, PlotRange -> {-1, 1}]
>OddFunctionQ[f_] := Module[{x}, f[x] + f[-x] === 0]
>EvenFunctionQ[f_] := Module[{x}, f[x] - f[-x] === 0]
>fs = {# &, #^3 &, Sin, Cos, xx, yy}
>OddFunctionQ /@ fs
>{True, True, True, False, False, False}
>EvenFunctionQ /@ fs
>{False, False, False, True, False, False}

The key to understanding what is going on is to look at what is
returned for each of the functions when fed a symbol with no
assigned value. For Sin we get,

In[11]:= Sin[z]

Out[11]= sin(z)

In[12]:= Sin[-z]

Out[12]= -sin(z)

That is Mathematica knows Sin[-z] == -Sin[z] which means doing
Sin[z]+Sin[-z] gives 0. So, your OddFunctionQ returns true. Now
look at xx[z] and xx[-z]

In[13]:= xx[z]

Out[13]= Piecewise[{{-1,
    Inequality[-(1/2), LessEqual, Mod[z, 1, -(1/2)],
          Less, 0]}, {1, Inequality[0, LessEqual, Mod[z, 1, -(1/2)],
          Less, 1/2]}}]

In[14]:= xx[-z]

Out[14]= Piecewise[{{-1,
    Inequality[-(1/2), LessEqual, Mod[-z, 1, -(1/2)],
          Less, 0]}, {1, Inequality[0, LessEqual, Mod[-z, 1, -(1/2)],
          Less, 1/2]}}]

In both cases Mathematica is returning the expression
unevaluated since until z has a value Piecewise cannot determine
what to return. And since both are returned unevaluated, the
subtraction/addition you do in either OddFunctionQ or
EvenFunctionQ is an undefined operation and consequently does
not evaluate to something that can be compared to 0. The net
result is the neither f[x]-f[-x] nor f[x]+f[-x] will ever be
identical to zero. So, both OddFunctionQ and EvenFunctionQ
should return False as they did.

Your function xx appears to have an identical output to the
built in function SquareWave. If your intent is to have xx
output a square wave, you can create a function xx that will
satisfy the testing you are doing in OddFunctionQ and
EvenFunctionQ as follows:


That is with these definitions:

In[16]:= OddFunctionQ[xx]

Out[16]= True

In[17]:= EvenFunctionQ[xx]

Out[17]= False

  • Prev by Date: Re: Evaluation control in Compile[]
  • Next by Date: Re: Evaluation control in Compile[]
  • Previous by thread: Re: Akima-Interpolation
  • Next by thread: Re: Even and Odd functions