Thread: Integration to infinity

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Integration to infinity

    Can anyone help? I have to integrate between 0 and infinity for cos(x)/sqrt(x)

    Code:
    #include<stdio.h>
    #include<math.h>
    
    #define PRECISION 0.001
    
    int main()
    {
    float x;
    float y;
    float z;
    float a;
    float h;
    
    printf("Enter trapezium height 'h':");
    scanf("%f", &h);
    x=0;
    a=0;
    do
    {
        y=(cos(x)/sqrt(x));
        if (x!=0)
        {
            a=a+(0.5*h*(y+z));
        }
        (z=y);
        (x=x+h);
    }
    while ((z<cos(x)/sqrt(x) - PRECISION) || (z>cos(x)/sqrt(x) + PRECISION));
    
    printf("integral between 0 and infinity=%f", a);
    
    }
    All I'm getting when I run this is 1.#INF00, and I don't know what that means

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    You're starting at x=0, right? cos(0)=1 and sqrt(0)=0, so what is cos(0)/sqrt(0) going to be?

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    Ah, I see your point. Thankyou

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Integration coding using simpsons rule
    By thintheherd in forum C Programming
    Replies: 2
    Last Post: 05-10-2010, 02:08 AM
  2. Integer infinity?
    By housguest in forum C Programming
    Replies: 1
    Last Post: 04-21-2008, 01:03 AM
  3. Numerical Integration
    By Crazed in forum C Programming
    Replies: 13
    Last Post: 03-03-2008, 03:01 PM
  4. how to set value equal to infinity
    By Downnin in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2005, 04:14 PM
  5. performing continuous integration
    By flight727 in forum C Programming
    Replies: 1
    Last Post: 12-05-2001, 03:23 PM