Inconsistent results for symbolic integration of >2 cosine factors

When I integrate the product of two cosine functions with integer arguments, I get an answer that appears correct. When I add a third, the solution simplifies to zero, which is not consistent with at least one case of numerical integration. This occurs with Ver 23.2 of SMT (2023b).
clear
syms m n p x
assume(in(m, 'integer') & in(n, 'integer') & in(p, 'integer'));
assumeAlso(m>=0 & n>=0 & p>=0);
assumptions
ans = 
%% Symbolic Solutions
% Expected
y_2cos_sym = simplify(int(cos(x*m)*cos(x*n), x, -pi, pi))
y_2cos_sym = 
% Unexpected
y_3cos_sym = simplify(int(cos(x*m)*cos(x*n)*cos(x*p), x, -pi, pi))
y_3cos_sym = 
0
%% Numerical Solutions
m = 0; n = 0; p = 0;
% Expected
y_2cos_num = int(cos(x*m)*cos(x*n), x, -pi, pi)
y_2cos_num = 
% Expected
y_3cos_num = int(cos(x*m)*cos(x*n)*cos(x*p), x, -pi, pi)
y_3cos_num = 

3 Comments

Yes, it's a bug. The case 0/0 is not treated correctly for the answer you get from
syms m n p x
assume(in(m, 'integer') & in(n, 'integer') & in(p, 'integer'));
assumeAlso(m>=0 & n>=0 & p>=0);
y_3cos_sym = int(cos(x*m)*cos(x*n)*cos(x*p), x, -pi, pi)
y_3cos_sym = 
You should report it to Technical Support.
Thanks, will do. For what it's worth, Maple 2023 seems to miss this too. Not sure about Mathematica.
clear all
syms m n p x
assume(in(m, 'integer') & in(n, 'integer') & in(p, 'integer'));
assumeAlso(m>=0 & n>=0 & p>=0);
assumptions
ans = 
%% Symbolic Solutions
% Expected
y_2cos_sym = (int(cos(x*m)*cos(x*n), x, -pi, pi))
y_2cos_sym = 
y_2cos_sym is returned as piecewise w/o using simplify.
I'm curious about this. I'm surprised that y_2cos_sym is returned as a piecewise function. In other cases I've run into with just a single variable int doesn't recognize special cases for integer parameters in the integrand, so I'm curious why it does so for y_2cos_sym
clear all
syms n integer
syms t w real
f(t) = sin(2*sym(pi)*2*t);
T = 1.4;
C(n) = int(f(t)*exp(-1j*2*sym(pi)*n*t),t,0,T)
C(n) = 
C(n) is not returned as piecewise, and n = -2 and n = 2 cause problems
try
C(2)
catch ME
ME.message
end
ans = 'Division by zero.'
even though C(n) is well defined for n = 2 (and n = -2)
C2 = int(subs(f(t)*exp(-1j*2*sym(pi)*n*t),n,2),t,0,T)
C2 = 
So why doesn't int return C(n) as a piecewise?
I'm going to guess that y_2cos_sym is a known special case by int but y_3cos_sym (and my C(n)) is not.

Sign in to comment.

Answers (0)

Products

Release

R2023b

Asked:

on 18 Feb 2024

Commented:

on 18 Feb 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!