Problems evaluating symbolic integral

3 views (last 30 days)
Joshua Wilson
Joshua Wilson on 2 Aug 2020
Commented: Joshua Wilson on 2 Aug 2020
I'm having issues evaluating the definite integral of a symbolic expression using MATLAB's Symbolic Toolbox:
syms t n
assume(n, 'integer')
expression = sin(3*t)^2 * cos(n*t);
value = int(expression, t, -pi, pi);
This returns that the integral is 0 everywhere, despite the fact that there should be a special case where the integral is non-zero at n = 6. When I don't make the assumption that 'n' is an integer, I get an expression that is singular at n = 6. Is there some way that I can adapt my code so that it returns the expected answer? For reference, I go on to take the sum of the integral expressions for increasing values of n using symsum(), and would like to avoid the case where I need to explicitly define these singular values of 'n'. I am trying to avoid evaluating this integral numerically, if at all possible.
  2 Comments
David Goodmanson
David Goodmanson on 2 Aug 2020
Hi Joshua,
Certainly value = 0 for integer n is a bad result.
But for unrestricted n, the result at n = 6 is not singular. The result is
value = -(36*sin(pi*n))/(n*(n^2 - 36)) = -(36*sin(pi*n))/(n^3 - 36n))
Both the numerator and denominator are zero at n = 6, and by l'hopital's rule the result is
-36*pi*cos(pi*6) / (3n^2 - 36) | n= 6 = -pi/2
which is correct.
Joshua Wilson
Joshua Wilson on 2 Aug 2020
Hi David,
Thanks for your response. This makes sense, I missed the fact that both the numerator and denominator being 0 would allow this to be handled. I suppose I can use the limit() function to evaluate the expressions properly.

Sign in to comment.

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!