Sine product integral

52 views
Skip to first unread message

Julien Hillairet

unread,
Mar 30, 2015, 7:40:34 PM3/30/15
to sy...@googlegroups.com
Dear all,

First of all, many thanks for Sympy, which is a great tools !


I try to integrate a product of two sinus functions such as :

f(x) = sin(pi*n/L*x) * sin(pi*m/L*x)

where n and m are two positive integer (and L>0). I've found the correct expected values (L/2 if m=n, 0 otherwise). But if I make a small change of variable, moving x to x+L/2, then Sympy fails to provide me an answer. Is there a way to "help" Sympy finding the correct solution ?

An example is below :

----

z = symbols('z')
m, n = symbols('m n', positive=True, integer=True)
L = symbols('L', positive=True, real=True)

def e1(z, n, L):
    k_n = n*pi/L
    return sin(k_n*(z))

def e2(z, n, L):
    k_n = n*pi/L
    return sin(k_n*(z+L/2))

Imn1 = integrate(fu(e1(z, n, L)*e1(z, m, L)), (z, 0, L))
Imn2 = integrate(fu(e2(z, n, L)*e2(z, m, L)), (z, -L/2, L/2))

---

In [16]: Imn1
Out[16]: Piecewise((L/2, m == n), (0, True))

In [17]: Imn2
Out[17]: Integral(sin(pi*m*(L/2 + z)/L)*sin(pi*n*(L/2 + z)/L), (z, -L/2, L/2))

Best regards,

Julien

Kalevi Suominen

unread,
Mar 31, 2015, 2:17:36 AM3/31/15
to sy...@googlegroups.com

It seems that SymPy can compute the integral if you write  sin(pi*m/2 + pi*m*z/L)  instead of
sin(pi*m*(L/2 + z)/L). Apparently its pattern matching does not cover the latter form. (fu will
not be needed.)

Kalevi Suominen

Julien Hillairet

unread,
Mar 31, 2015, 10:40:21 AM3/31/15
to sy...@googlegroups.com
Indeed. Thank you for this tips.

Julien
Reply all
Reply to author
Forward
0 new messages