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

Elliptic Integrals * request help *

  1. Jun 11, 2010 #1
    1. The problem statement, all variables and given/known data
    I need to write a program (or use one that's already written) to compute the elliptic integral of the 1st and 2nd kind - ie F and E respectively. Please note that this is NOT a homework assignment. Thus, I do not actually need to write the code, and will be happy to use something that's already written. (In fact, I would be surprised if this hasn't been done quite a lot already, I just can't seem to find any code/library)!

    2. Relevant equations
    No equations. I looked to see if I could find this code already implemented in C or Fortran, and no luck thus far. So, I decided to try and see if I could get my own code to work via Numerical Recipes in C. I wrote the code, and the code is giving me a value of 2, always. Clearly it's not working.

    3. The attempt at a solution
    I will be happy to e-mail someone my code if he/she is willing to look at it (it's written in C++). Consequently, if anyone knows if this is already implemented in some library, please let me know. Also, please note that I am a beginner programmer, so I apologize ahead of time if my questions are "simple"! Thank you.
  2. jcsd
  3. Jun 12, 2010 #2


    User Avatar
    Science Advisor

    Probably nobody is going to want to wade through your code and figure out what you did wrong. If it's always giving 2, you probably have something simple wrong. I suggest you simplify the problem to trying to calculate something easy (like x^2 or cos(x)), and get this working, then move on to more complicated functions. The Wolfram functions site is a great resource for formulas on functions like this:

  4. Jun 17, 2010 #3
  5. Jun 19, 2010 #4
    Not sure if you're looking for "complete" elliptic integrals or not. If you want the complete elliptic integrals of first and second kind, there's a very efficient algorithm using arithmetic-geometric means. I discuss it on my site, and have example code in Open Office Basic and Javascript.
    http://electronbunker.sasktelwebsite.net/CalcMethods1a.html [Broken]
    Last edited by a moderator: May 4, 2017
  6. Jun 22, 2010 #5
    Thanks everyone for your helpful replies. Shortly after I posted I figured out what I did wrong (isn't that always the case :)

    I checked my results with Abramowitz and Stegun and they agree perfectly. I would eventually like to get the GNU library to work, I haven't done that yet.


Share this great discussion with others via Reddit, Google+, Twitter, or Facebook