Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:19:20+00:00 2026-06-18T10:19:20+00:00

here is my work. i cannot figure out why when i make n=3 in

  • 0

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 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:19:21+00:00Added an answer on June 18, 2026 at 10:19 am

    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 to forget() and time(), if you wish.

    I figured that you wanted your various ffsN procedures to add from 1 to N, rather than just add the Nth term (from N to N). So I made the last argument of ffs be 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 simplify to the exact symbolic coefficients, which collapses them to something more expected. (Think of orthogonality.) I also used value and inert Int * Sum rather than active int and sum or add, 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.

    restart:
    f:=x->sin(3*x)/x:
    an:=1/Pi*Int(f(t)*cos(n*t),t=-Pi..Pi):
    bn:=1/Pi*Int(f(t)*sin(n*t),t=-Pi..Pi):
    ffs:=unapply(Sum(an*cos(n*x)+bn*sin(n*x),n=1..N),[x,N]):
    
    a0:=1/(2*Pi)*int(f(t),t=-Pi..Pi):
    
    a0+simplify(value(ffs(x,1)));
    evalf(%);
    
    seq(a0+simplify(value(ffs(x,i))),i=0..3);
    
    seq(evalf(a0+ffs(x,i)),i=0..3);
    
    forget(evalf): forget(int): forget(`evalf/int`):
    forget(Si): forget(Ci): forget(ffsrecursive): forget(value):
    st:=time():
    G5:=[seq(a0+simplify(value(ffs(x,i))),i=0..5)]:
    plot(G5,x=-Pi..Pi);
    time()-st;
    
    forget(evalf): forget(int): forget(`evalf/int`):
    forget(Si): forget(Ci): forget(ffsrecursive): forget(value):
    st:=time():
    H5:=[seq(evalf(a0+ffs(x,i)),i=0..5)]:
    plot(H5,x=-Pi..Pi);
    time()-st;
    
    ffsrecursive:=proc(x,N) option remember, system;
      if N<=0 then return evalf(a0);
      else
         return procname(x,N-1)+evalf(eval(an*cos(N*x)+bn*sin(N*x),n=N));
      end if;
    end proc:
    
    ffsrecursive(x,3);
    
    ffsrecursiveexact:=proc(x,N) option remember, system;
      if N<=0 then return a0;
      else
         return procname(x,N-1)+simplify(value(eval(an*cos(N*x)+bn*sin(N*x),n=N)));
      end if;
    end proc:
    
    ffsrecursiveexact(x,3);
    
    forget(evalf): forget(int): forget(`evalf/int`):
    forget(Si): forget(Ci): forget(ffsrecursive): forget(value):
    st:=time():
    S5exact:=[seq(ffsrecursiveexact(x,i),i=0..5)]:
    plot(S5exact,x=-Pi..Pi);
    time()-st;
    
    forget(evalf): forget(int): forget(`evalf/int`):
    forget(Si): forget(Ci): forget(ffsrecursive): forget(value):
    st:=time():
    S5:=[seq(ffsrecursive(x,i),i=0..5)]:
    plot(S5,x=-Pi..Pi);
    time()-st;
    
    # difference w.r.t. f(x)
    forget(evalf): forget(int): forget(`evalf/int`):
    forget(Si): forget(Ci): forget(ffsrecursive): forget(value):
    st:=time():
    plot([seq(ffsrecursive(x,i)-f(x),i=15..19)],x=-Pi..Pi);
    time()-st;
    
    # difference w.r.t. f(x)
    forget(evalf): forget(int): forget(`evalf/int`):
    forget(Si): forget(Ci): forget(ffsrecursive): forget(value):
    st:=time():
    plot([seq(a0+simplify(value(ffs(x,i)))-f(x),i=15..19)],x=-Pi..Pi);
    time()-st;
    
    # difference w.r.t. f(x)
    forget(evalf): forget(int): forget(`evalf/int`):
    forget(Si): forget(Ci): forget(ffsrecursive): forget(value):
    st:=time():
    H15_19diff:=[seq(a0+evalf(ffs(x,i))-f(x),i=15..19)]:
    plot(H15_19diff,x=-Pi..Pi);
    time()-st;
    

    [addendum] The submitter asked for just one simple approach. Here is the exact, non-recursive approach (of the 4 above).

    restart:
    
    f:=x->sin(3*x)/x:
    an:=1/Pi*Int(f(t)*cos(n*t),t=-Pi..Pi):
    bn:=1/Pi*Int(f(t)*sin(n*t),t=-Pi..Pi):
    
    ffs:=unapply(Sum(an*cos(n*x)+bn*sin(n*x),n=1..N),[x,N]):
    
    a0:=1/(2*Pi)*int(f(t),t=-Pi..Pi):
    
    G5:=seq(a0+simplify(value(ffs(x,i))),i=0..5);
    
    plot([f(x), G5],x=-Pi..Pi,
         legend=[f(x),"n=0","n=1","n=2","n=3","n=4","n=5"],
         color=[black,gold,cyan,green,blue,magenta,red]);
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make simpleModal jquery script to work, but cannot figure out what
I'm sure I've overlooked something here but cannot work it out. There's white space
I'm new to C++ and I cannot figure out how pointers work in relation
I think I'm having a brain freeze here but I cannot figure out the
I cannot get this to work, here is code that I found in another
I tried this JavaScript but it doesn't work - here I need to change
Trying to copy the msdn refernce here doesn't work and gives an error I
I can't make this scenario work. Here's the pattern- [DataContract] /*abstract*/ class BaseT {
Here is the skeleton of some basic code I am writing to make a
I'm probably making a newbie mistake here, but I can't figure out how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.