I have functions of x
, where x
is the polar angle of spherical coordinates, i.e. 0 < x < Pi
. Some of the functions are of even symmetry about the equator x = Pi/2
(such as Sin[x]
), and other functions are of odd symmetry about x = Pi/2
(such as Sin[x]Cos[x]
) (Just Plot
them to see.) Can one use Mathematica to eliminate odd functions from a sum of even and odd functions? For example, as a test, can one eliminate the odd function from the sum Sin[x] + Sin[x]Cos[x]
?
$\begingroup$
$\endgroup$
$\begingroup$
$\endgroup$
(* Check if f is odd/even around an interval of length d centered around c *)
evenQ[f_, c_: Pi/2, d_: Pi] := Integrate[Abs[f[c + x] - f[c - x]], {x, 0, d/2}] == 0
oddQ[f_, c_: Pi/2, d_: Pi] := Integrate[Abs[f[c + x] + f[c - x]], {x, 0, d/2}] == 0
sum = Sin[x] + Sin[x] Cos[x] + Cos[x] + Exp[x]
(* Sum to list, elements to functions, remove odd ones, back to sum *)
Plus @@ DeleteCases[Map[Function[x, #] &, List @@ sum], _?(oddQ[#] &)]
% /. Function[x, f_] :> f
(* Function[x, E^x] + Function[x, Sin[x]] *)
(* E^x + Sin[x] *)
I wanted oddQ
and evenQ
to take a function as argument so there is some mucking about making the expression in the sum into functions.
If you want to keep only even functions (that is, not leave stuff like Exp
in) use Cases[..., _?(evenQ[#]&)]
instead.
If the functions are slow to integrate change to NIntegrate
with some appropriate AccuracyGoal
-
1$\begingroup$ Thanks @ssch. That seems like a very nice general way to do this. I'll check it out. But for this limited case, wouldn't it be easier to just use the formula for F[x] above? $\endgroup$ – Skybobcat Feb 6 '13 at 16:37
-
antisymmetrize[expr_, {x_, x0_}] := (expr - (expr /. x -> 2 x0 - x))/2
$\endgroup$ – Xerxes Feb 6 '13 at 6:45