Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2862 > unrolled thread

Re: Even and Odd functions

Started byBill Rowe <readnews@sbcglobal.net>
First post2011-06-01 08:33 +0000
Last post2011-06-01 08:33 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Even and Odd functions Bill Rowe <readnews@sbcglobal.net> - 2011-06-01 08:33 +0000

#2862 — Re: Even and Odd functions

FromBill Rowe <readnews@sbcglobal.net>
Date2011-06-01 08:33 +0000
SubjectRe: Even and Odd functions
Message-ID<is4tgn$b46$1@smc.vnet.net>
On 5/31/11 at 7:48 AM, yitzhakbg@gmail.com (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:

xx[t_]:=SquareWave[t]
xx[-t_]:=-SquareWave[t]

That is with these definitions:

In[16]:= OddFunctionQ[xx]

Out[16]= True

In[17]:= EvenFunctionQ[xx]

Out[17]= False

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web