Why does this program give -1.#IND

Hi guys, why does this code give -1.#IND? I've tried evaluating cos(i*dN) by itself and it doesn't return 0 for pi/2. I'd appreciate your help very much.

BTW, this is just simpson's rule

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

double modbesselfunc(double mu, double z, double n){
       
       double sum = 0;
       double pi = M_PI;
       double a=0;
       double b = pi/2.0;
       double dN;
       
       dN = (b-a)/n;
       
       for(int i=0; i<=n; i++){
   
       if(i%2==0){
                  
                  if(i == 0 || i == n)
                       sum +=sin(z*sinh(tan(i*dN)))*sin(mu*tan(i*dN))*(1.0/pow(cos(i*dN),2.0));
                  
                  else
                      sum += 2.0*sin(z*sinh(tan(i*dN)))*sin(mu*tan(i*dN))*(1.0/pow(cos(i*dN),2.0));
                  } 
       
       else
           sum += 4.0*sin(z*sinh(tan(i*dN)))*sin(mu*tan(i*dN))*(1.0/pow(cos(i*dN),2.0));                
       }
       
       sum = (dN/3.0)*sum;
       
       return (1.0/sinh(0.5*pi*mu))*sum;
}

int main(){
    
    cout << modbesselfunc(2.0,sqrt(8*0.06)/0.3,1000) << endl;
    
 system("PAUSE");   
 return(0);   
}
Last edited on
1
2
if(i == 0 || i == n)
                       sum +=sin(z*sinh(tan(i*dN)))*sin(mu*tan(i*dN))*(1.0/pow(cos(i*dN),2.0));
when i==n you are trying to calculate tan(pi/2);
Topic archived. No new replies allowed.