Here is an example: sage: f = lambda x:x^2 sage: f = Piecewise([[(-1,1),f]]) sage: x = var("x") sage: n = var("n") sage: f.fourier_series_cosine_coefficient(n,1) ((2*pi^2*n^2 - 4)*sin(pi*n) + 4*pi*n*cos(pi*n))/(pi^3*n^3) sage: maxima.eval('declare(n,integer)') 'done' sage: f.fourier_series_cosine_coefficient(n,1) 4*(-1)^n/(pi^2*n^2)
On Tue, Apr 15, 2008 at 11:58 AM, James Morrow <[EMAIL PROTECTED]> wrote: > Hello David, > > I am interested in the nth term of the Fourier series. In some cases there > are simple formulas for that term (for example if the function is > f(x)=x^2 on the interval [-pi,pi]). However I can't figure out how to tell > sage to do this. I can ask it to compute int_{pi}^{pi} f(t)sin (n*t)dt)\pi, > but it doesn't know that n is an integer and hence doesn't know that > cos(pi*n) is (-1)^n or that sin(pi*n)=0. I can't figure out how to get it > to simplify the answer. > > Jim > > > > > On Tue, Apr 15, 2008 at 4:02 AM, David Joyner <[EMAIL PROTECTED]> wrote: > > > The module piecewise.py has fairly extensive functionality for the > > computation of Fourier series of piecewise defined periodic functions. > > It even allows filters. There are examples at > > http://www.sagemath.org/doc/html/const/node12.html > > > http://www.sagemath.org/hg/sage-main/file/cc1e12a492fc/sage/functions/piecewise.py > > I think it is well documented but if tere are any questions, please just > ask. > > > > On Mon, Apr 14, 2008 at 7:47 PM, William Stein <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > ---------- Forwarded message ---------- > > > From: James Morrow <[EMAIL PROTECTED]> > > > Date: Mon, Apr 14, 2008 at 4:20 PM > > > Subject: fourier series > > > To: [EMAIL PROTECTED], William Stein <[EMAIL PROTECTED]> > > > > > > > > > Hello, > > > > > > How do I use sage to compute a Fourier series? The general question > > > is: How to compute the nth term? I guess I have to use maxima. How > > > do I call maxima and then give it the imput? I don't just want (say) > > > the 5th term, but the nth term. Do I make n a variable (integer > > > variable)? Maybe I can't do it in this generality, but for instance > > > this amounts to computing (int_{pi}^{pi} f(t)sin (n*t)dt)\pi, where I > > > declare n is an integer variable. > > > > > > Jim > > > > > > > > > -- > > > William Stein > > > Associate Professor of Mathematics > > > University of Washington > > > http://wstein.org > > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---