Reputation: 5877
Here's something I'm trying out based on this page: http://tutorial.math.lamar.edu/Classes/DE/FourierSineSeries.aspx
from sympy import *
f = Function('f')
B = IndexedBase('B')
x, L = symbols('x L', real=True)
n = Symbol('n', integer=True)
n = Idx(n, (0, oo))
Bn = Indexed('B', n)
m = Symbol('m', integer=True)
expr = sin(m*pi*x/L)
lhs = integrate(f(x)*expr, (x,-L,L))
rhs = Sum(Bn*integrate(expr*sin(n*pi*x/L), (x,-L,L)), n)
It crashes on the last line, stating that:
TypeError: Idx object requires an integer label.
The Idx object does, however, have an explicitly set integer label. Furthermore, an expression as Sum(Bn*sin(n*pi*x/L),n)
works with no problems.
Is the fact that I am putting an integral inside the sum problematic? Or is it just a minor syntax problem?
Upvotes: 1
Views: 94
Reputation: 1526
The issue is because the variable n
is used both as a Symbol
and a Idx
object. The following code does not throw an error. (Though I am not sure if it serves your purpose)
from sympy import *
f = Function('f')
B = IndexedBase('B')
x, L = symbols('x L', real=True)
n = Symbol('n', integer=True)
n_index = Idx(n, (0, oo))
Bn = Indexed('B', n)
m = Symbol('m', integer=True)
expr = sin(m*pi*x/L)
lhs = integrate(f(x)*expr, (x,-L,L))
rhs = Sum(Bn*integrate(expr*sin(n*pi*x/L), (x,-L,L)), n_index)
Upvotes: 1