here is my work. i cannot figure out why when i make n=3 in the Fourier series, maple spits out a division by zero error.. i need some suggestions to get by this. The fourier series for n=1 and n=2 graph perfectly. This only starts to become a problem when n=3 and on. Im thinking it may be an issue with the way i define f(x), but ive tried numerous ways to define it, and i get the same result.
New to maple, so go easy on me.
here is the link to some pictures of my work:
page1: http://tinypic.com/r/34iqmfa/6
page2: http://tinypic.com/r/2rzruvm/6
All the
forget()calls in the code are just there to try and clear previously stored results, so that the timing comparisons might be more fair. You can remove all the calls toforget()andtime(), if you wish.I figured that you wanted your various
ffsNprocedures to add from 1 to N, rather than just add the Nth term (from N to N). So I made the last argument offfsbe i=1..N rather than i=N similar to what you had.You can approach this in a purely exact symbolic way, or you can compute the coefficients numerically. And you can also try to re-use coefficients (exact symbolic, or floats) computed in previous calls that added fewer terms. This makes a measurable performance difference if you are going to compare the plots using “the sum of first 2 terms”, “the sum of the first 5 terms”, etc. One way to get such re-use is by using a recursive procedure with
option remember, which is done below for both exact and float coefficient approaches.I applied
simplifyto the exact symbolic coefficients, which collapses them to something more expected. (Think of orthogonality.) I also usedvalueand inertInt*Sumrather than activeintandsumoradd, but that was just so I could also get float coefficients without doing any symbolic work.This runs in Maple 15. Shout if it doesn’t run, and then please state your version.
[addendum] The submitter asked for just one simple approach. Here is the exact, non-recursive approach (of the 4 above).