Post Reply 
How to change integration variable ?
12-15-2019, 02:18 AM (This post was last modified: 12-15-2019 02:22 AM by hamorabi.)
Post: #1
How to change integration variable ?
I'm trying to write a function that generates the general form of the Fourier series coefficients of a periodic waveform that is piece-wise defined.

This is the code I'm using at the moment.

PHP Code:
def fseries(fxn_,var_,ll,uu):
    if (
type(fxn_) != DOM_LIST):
fxn_ = [fxn_]
uu = [uu]
    if (
len(fxn_) != len(uu)):
        return (
"Unequal list sizes")
a_0a_nb_n 000

for i in range(0,len(uu)):
a_0 += 2/T*int(fxn_[i],var_,ll,uu[i])
a_n += 2/T*int(fxn_[i]*cos(n*var_*ω),var_,ll,uu[i])
b_n += 2/T*int(fxn_[i]*sin(n*var_*ω),var_,ll,uu[i])
ll uu[i]
a_0 simplify(a_0)
a_n simplify(a_n)  
b_n simplify(b_n)    

For example, let's say the periodic waveform is defined as:
x, from 0 to 1
1, from from 1 to 2

This is how it I can call the function:

The problem I'm having is when it comes to passing the independent variable. I want to allow for flexibility in choosing any variable letter. At the moment, the code runs but it doesn't seem to recognize the variable letter (see first entry in attached image). Now, if I hard code the variable name in the code (change all var_x to x), it works fine (see second entry in attached image). I've tried different things such as defining the variable as a symbol, substituting, etc, but nothing seems to work. I'm a bit baffled at the moment.

Attached File(s) Thumbnail(s)
Find all posts by this user
Quote this message in a reply
Post Reply 

User(s) browsing this thread: 1 Guest(s)