#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0

    Smile I need to integration code in c language


    Hi

    i need to code in c language for the integration of 1/x from 1 to 10, i want it .

    please help me
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0
    As I understand it you have to write a program which will display
    the values of function 1/x from 1 to 10.
    Code:
    #include <stdio.h>
    
    int main()
    {
        float x;
        for (x = 1.0; x <= 10; x++)
            printf("f(%f) = %f\n", x, 1/x);
    
        return 0;
    }
    good luck! :)
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Numeric methods for approximating integration are many and very well known; eg, Trapazoidal Rule, Simpson's Rule. Learn one and implement it.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480

    Test value


    Your answer, if I remember my calculus correctly, should be about 2.3.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    Good point, b49P23TIvg. Does he need to use an approximation method or can he just apply his knowledge of what the integral of 1/x is?
  10. #6
  11. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,109
    Rep Power
    1802
    Originally Posted by aybek
    As I understand it you have to write a program which will display the values of function 1/x from 1 to 10.
    I am pretty sure you don't understand it. That is not integration.
  12. #7
  13. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,109
    Rep Power
    1802
    This is a C programming site, not a maths site. You might get a larger number of answers if you did the maths, so those that can code but are not necessarily mathematicians might help.

    That said the definite integral of 1/x for the range a to b is equal to ln(|b|) - ln(|a|). In the standard C math library the log() function computes the natural logarithm (as opposed to log10() for base 10 logs). So:

    Code:
    double i = log(10) - log(1) ;
    ln(1) is zero, so in fact just i = log(10) in this case.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    thank you all for that

    but the answer of
    clifford maybe its right

    thanks again

    Comments on this post

    • b49P23TIvg agrees : Yeah, maybe clifford got the right answer.

IMN logo majestic logo threadwatch logo seochat tools logo