What would be the correct way to tell Mathematica that
Integrate[Sin[3 x] Sin[n x], {x, 0, Pi}]
Should not be zero when n
is an integer for all n
in the above? Since when n=3
the answer should be Pi/2
and zero for all other n
values.
But Mathematica does not seem to detect this, even when told that n
is integer:
ClearAll[x,n]
Integrate[Sin[3 x] Sin[n x], {x, 0, Pi},Assumptions -> Element[n, Integers] && n > 0]
% /. n -> 3
And if
Assuming[Element[n,Integers]&&n>0,Integrate[Sin[3 x] Sin[n x],{x,0,Pi}]]
(*0*)
While
n=3;
Integrate[Sin[3 x] Sin[n x],{x,0,Pi}]
(* Pi/2*)
The question is, is it the programmer responsibility to tell Mathematica that sin(3 x)*sin(n x)
is special case when n=3
? May be make a function around it, something like
foo[n_Integer]:=
If[n==3,
Integrate[Sin[3 x]^2,{x,0,Pi}],
Integrate[Sin[3 x] Sin[n x],{x,0,Pi}]] (*0*)
];
But I do not think the above is a good way to do in in general.
I think a special rule is needed to tell Mathematica about orthogonality of trig functions, and then ask Integrate to use this rule? But how to do this?
The question is: Should Mathematica have been able to automatically handle the special case of n=3
above? If not, what would be the best way to add a rule to tell Integrate to do this?
Assumtions
insideIntégrate
, but does toAssuming
. I mean, I get the correct result for assumptions by usingAssuming
instead. $\endgroup$