numerical integration of sin(x)/x

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanctus
    New Member
    • Mar 2007
    • 84

    numerical integration of sin(x)/x

    I'm trying to write a simulation program in cosmology and I'm stuck because I need to calculate integrals of the form sin(x)/x.
    Has anyone a source code for this? Or is there an easy way to do it in the gsl (I know that there is the monetcarlo integration there, but I need something more direct)?

    Thanks in advance
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    For sin(x)/x approximate sin(x) as a power series: x^1/1! - x^3/3! + x^5/5! ... and
    divide by x.Finally take the anti derivative of that polynomial.

    Here's a nice link.

    kind regards,

    Jos

    Comment

    • emaghero
      New Member
      • Oct 2006
      • 85

      #3
      Originally posted by sanctus
      I'm trying to write a simulation program in cosmology and I'm stuck because I need to calculate integrals of the form sin(x)/x.
      Has anyone a source code for this? Or is there an easy way to do it in the gsl (I know that there is the monetcarlo integration there, but I need something more direct)?

      Thanks in advance
      If you are looking for an easily implementable and accurate numerical integration scheme use Gaussian Quadrature. A google search will throw up any number of sites on the subject.

      Also the integral of the function Sinc[x]=Sin[x]/x is called the Sine Integral Si[x]. Tables of this integral have been computed and can be found in CRC Standard Mathematical Tables. In these tables you will also find lots in info on the various numerical integration schemes.

      If you want the algorithms for Gaussian Quadarature, or any other numerical integrator, consult "Numerical Recipes in C" by Press et al. It is avaliable for download at http://www.nr.com/

      Comment

      • sanctus
        New Member
        • Mar 2007
        • 84

        #4
        Josah, I thought about that, but it seemed to me that a problem arises as soon as x takes a value bigger than 1 (higher power=more importance there...), ie you would have to compute the limit of the series. But I have to ponder it a bit further, maybe it works (I just say it didn't seem to me sor far, but now I've been working for more than 10 hours so I let this sleep until tomorrow).

        Emaghero, I need to this integral for many different x (actually as many as I can before my pc overheats as I have to do some Monte Carlo simulation), so the table isn't of much use as I would have to enter it manually (unless there is a list somewhere one could use). For the same reason as said at the end of the above paragraph, I'll look into the Gaussian Quadrature tomorrow.

        But thank you both very much, now I can sleep well knowing that there is a quicker way than writing the code myself (which is permitted as my work is in physics and not informatics, so it isn't cheating :) )

        Comment

        • sanctus
          New Member
          • Mar 2007
          • 84

          #5
          Thanks for the link to the algorithms emaghero, it worked (after 5h of work figuring out the way to adapt it to my needs...).
          Now I have to figure how to change the makefile to include a new header file...never done this, but tomorrow is another day...

          Comment

          Working...