您可能想要修改您的期望(或您的假设)以涵盖另一个极端情况,因为如果n1=n2=0
那么积分应该等于2*Pi
.
restart:
int(cos(0*x)*cos(0*x),x=0..2*Pi);
2 Pi
int(cos(3*x)*cos(-3*x),x=0..2*Pi);
Pi
int(cos(2*x)*cos(2*x),x=0..2*Pi);
Pi
ans1 := int(cos(n1*x)*cos(n2*x),x=0..2*Pi,AllSolutions)
assuming n1::integer, n2::integer;
piecewise(n1 - n2 = 0, Pi, 0) + piecewise(n1 + n2 = 0, Pi, 0)
simplify(ans1) assuming n1::integer, n2::integer, n1=n2, n1=0;
2 Pi
simplify(ans1) assuming n1::integer, n2::integer, n1=n2, n1<>0;
Pi
simplify(ans1) assuming n1::integer, n2::integer, n1<>n2, n1<>-n2;
0
您可能还想在n1
和n2
都是正整数的假设下考虑积分(它有一个更简单的条件结果,甚至可能是您的想法)。
ans2 := int(cos(n1*x)*cos(n2*x),x=0..2*Pi,AllSolutions)
assuming n1::posint, n2::posint;
piecewise(n1 - n2 = 0, Pi, 0)
simplify(ans2) assuming n1=n2;
Pi
simplify(ans2) assuming n1<>n2;
0