Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Fourier approximation with polynomial

  1. Feb 21, 2012 #1
    1. The problem statement, all variables and given/known data

    Approximate the function [itex]f(x)=sin(\pi x)[/itex] on the interval [itex][0,1][/itex] with the polynomial [itex]ax^{2}+bx+c[/itex] with finding a, b and c.

    2. Relevant equations



    [itex]a_n=\frac{1}{\pi}\int^{\pi}_{-\pi}f(x)cos(nx)dx , (n\geq1)[/itex]

    [itex]b_n=\frac{1}{\pi}\int^{\pi}_{-\pi}f(x)sin(nx)dx , (n\geq1) [/itex]

    3. The attempt at a solution

    I understand that this is just a matter of filling in the equations but I just don't seem to get it right. I get:


    [itex]a_{n}=-cos(\pi\pi)cos(\pi n)-\frac{n}{\pi}sin(\pi\pi)sin(\pi n)[/itex]

    [itex]b_{n}=-cos(\pi\pi)sin(\pi n)-\frac{n}{\pi}sin(\pi\pi)cos(\pi n)[/itex]

    I think I need to simplify this and I don't know how to, plus then I'm not sure how to use it.
    Thank you in advance.
    Last edited: Feb 21, 2012
  2. jcsd
  3. Feb 21, 2012 #2
    If n is in the natural numbers, what is sin(n*pi) equal to?

    Equally, what is cos(n*pi) equal to?

    Although I'm not entirely sure why you want to use a fourier series here.
    Last edited: Feb 21, 2012
  4. Feb 21, 2012 #3
    Okay so now I get:

    [itex]a_{n}=\pm cos(\pi^{2})[/itex]
    [itex]b_{n}=\pm \frac{n}{\pi}sin(\pi^{2})[/itex]

    And this will give me:

    [itex]f(x)=0+\sum^{\infty}_{n=1}(\pm cos(\pi^{2})cos(nx)+(\pm \frac{n}{\pi}sin(\pi^{2})sin(nx)))[/itex]

    And when do I use the interval [itex][0,1][/itex] and how?

    Thank you for the help!

    Ps. The assignment was to Fourier approximate. I forgot to mention that in the original post.
  5. Feb 21, 2012 #4

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    Your formulas are incorrect. If you want a Fourier series on [0,1] all your integrals must go from x = 0 to x = 1 and the series will involve sin(2nπx), cos(2nπx), not sin(nx) and cos(nx). That said: why do you want to use Fourier series? But, a more fundamental question is: how do you measure the quality of an approximation? When can you say that one approximation is better than another? How can you define a "best" approximation?

  6. Feb 21, 2012 #5


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    And, to add to that, you aren't asked to approximate your ##\sin(\pi x)## with sines and cosines. You want ##\sin(\pi x)\doteq ax^2+bx+c##.
  7. Feb 21, 2012 #6
    The assignment is to Fourier approximate.

    I've got these formulas in my notes:

    For a function with period T and T=2L we have:

    [itex]f(x)=a_{0}+\sum^{\infty}_{n=1}(a_{n}cos(\frac{n\pi x}{L})+b_{n}sin(\frac{n\pi x}{L}))[/itex]


    [itex]a_{n}=\frac{1}{L}\int^{L}_{-L}f(x)cos(\frac{n\pi x}{L})dx , (n\geq1)[/itex]

    [itex]b_{n}=\frac{1}{L}\int^{L}_{-L}f(x)sin(\frac{n\pi x}{L})dx , (n\geq1)[/itex]

    So I just plugged in [itex]L=\pi[/itex] because [itex]T=2L=2\pi[/itex].

    Is that incorrect? To be fair I don't understand how to use the interval [itex][1,0][/itex] so am I supposed to integrate with it? Then why do I have the formulas from above if they are incorrect?
    Thank you!
  8. Feb 21, 2012 #7

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    Your general formulas are correct, but you are using them incorrectly in your example. If you have f(x) for x in the interval [0,1] you can look instead at g(z) = f(z + 1/2) for z in [-1/2,1/2]. Now take L = 1/2 in your Fourier formulas, applied to g(z). You will have a series containing sin(nπz/L) = sin(2nπx - πn) = +-sin(2πnx) and cos(nπz/L) = +-cos(2πnx).

    Anyway: you still have not explained why, in your first posting, you said you want to approximate f(x) "with the polynomial ax^2+bx+c with finding a, b and c" (you did use the word "Fourier" but I really don't understand why). The expression ax^2+bx+c is not a Fourier series; it is a polynomial.

  9. Feb 21, 2012 #8
    Hmm okay, well I'm supposed to approximate f(x) with the polynomial with a method called least sum of squares or something like that. It's hard to translate it.

    Okay I will try to do it with g(z) now. :smile:
  10. Feb 21, 2012 #9


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Why? Do you have a lot of extra time on your hands and just want to practice getting Fourier Coefficients even though it has nothing to do with your problem? Do you understand that you are working on a "solution" that has nothing to do with your stated problem?
  11. Feb 21, 2012 #10
    Okay I thought about what you said with g(z) but I just used f(x) and L=1/2. I hope that was okay.

    So this is what I got:


    [itex]a_{n}=\frac{-cos(\pi-2\pi n)}{(\pi-2\pi n)}-\frac{cos(\pi+2\pi n}{(\pi+2\pi n)}=\frac{cos(2\pi n)}{(\pi-2\pi n)}+\frac{cos(2\pi n}{(\pi+2\pi n)}[/itex]

    [itex]b_{n}=\frac{sin(2\pi n)}{(\pi-2\pi n)}+\frac{sin(2\pi n)}{(\pi+2\pi n)}[/itex]

    Which gives me:

    [itex]f(x)=\sum^{\infty}_{n=1}((\frac{1}{\pi(1-2n)}+\frac{1}{\pi(1+2n)})(cos(2\pi nx)(cos(2\pi n)+sin(2\pi nx)sin(2\pi n))=\sum^{\infty}_{n=1}(\frac{1}{\pi(1-2n)}+\frac{1}{\pi(1+2n)})(cos(2\pi nx-2\pi n))[/itex]

    Does this make any sense?
  12. Feb 21, 2012 #11


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    IF your problem was to express ##\sin(\pi x)## as a Fourier Series on [0,1] you would try to find ##a_n## and ##b_n## to get$$
    \sin(\pi x) = a_{0}+\sum^{\infty}_{n=1}(a_{n}cos(n\pi x)+b_{n}sin(n\pi x))$$and if you worked it correctly you would get ##a_n=0## and ##b_n=0## except for ##b_1=1##, which would give an identity for ##\sin(\pi x)##. It is its own finite Fourier Series.

    But that has nothing to do with your problem. You have never stated it fully, but I'm guessing you are supposed to minimize$$
    \int_0^1(\sin(\pi x) - ax^2-bx-c)^2\, dx$$by choosing the appropriate values for ##a,b,c##.
  13. Feb 22, 2012 #12
    LCKurtz thank you for your help.

    I used a totally different method after all this, finding a, b and c with linear algebra.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook