Fourier Series using fourie.mac




On Tue, 28 Jul 2009, Rafa Topolnicki wrote:

< Leo Butler pisze:
< > 
< > On Mon, 27 Jul 2009, Rafa? Topolnicki wrote:
< > 
< > < Hi,
< > < 
< > < During testing Fourier Series Expansion in maxima I found a problem I 
< > < can't cope with.
< > < 
< > < (%i3)                            load(fourie)
< > < (%o3)         /usr/share/maxima/5.18.1/share/calculus/fourie.mac
< > < (%i4)                         f(x) := abs(sin(x))
< > < (%o4)                         f(x) := abs(sin(x))
< > < (%i5)                    flist : fourier(f(x), x, %pi)
< > <                                           2
< > < (%t5)                              a  = ---
< > <                                      0   %pi
< > < 
< > <                       cos(%pi n)   cos(%pi n)      1         1
< > <                    2 (---------- - ---------- + ------- - -------)
< > <                        2 n + 2      2 n - 2     2 n + 2   2 n - 2
< > < (%t6)        a  = -----------------------------------------------
< > <                n                         %pi
< > < 
< >  
< > The easiest thing to do would be to add a line
< > 
< > %t6 : a[n] = if n=1 then 'limit( subst(n=_n,rhs(%t6)),_n,n ) else
< > %rhs(%t6);
 
You need to overcome the evaluation rules in sum. Here is one way to do
this using a lambda-function:

(%i2) load("fourie");
(%o2) "/home/work/maxima/maxima-5.18.1-clisp/share/calculus/fourie.mac"
(%i3) f(x):=abs(sin(x));
(%o3) f(x):=abs(sin(x))
(%i4) flist : fourier(f(x),x,%pi);
(%t4) a[0] = 2/%pi

(%t5) a[n] =
2*(cos(%pi*n)/(2*n+2)-cos(%pi*n)/(2*n-2)+1/(2*n+2)-1/(2*n-2))/%pi

(%t6) b[n] = 0

(%o6) [%t4,%t5,%t6]
(%i7) %t5 : a[n] = 'apply(lambda([s], if s=1 then 0 else
rhs(''%t5)),[n]);
(%o7) a[n] = 'apply(lambda([s],
                           if s = 1 then 0
                               else rhs(
                               a[n] = 2*(cos(%pi*n)/(2*n+2)
                                        -cos(%pi*n)/(2*n-2)+1/(2*n+2)
                                        -1/(2*n-2))
                                    /%pi)),[n])
(%i8) fourexpand(flist,y,%pi,3)$
(%i9) ev(%,nouns);
(%o9) 2/%pi-4*cos(2*y)/(3*%pi)


Leo

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.