-2
$\begingroup$

What I wanna solve it the problem following ( by quadrature method ) enter image description here

I want to get two arrays of data ( z & tau ) from z[0], tau[0] to z[2249], tau[2249].

Since the integrand diverges at z=0.9, 1.125, I need to tame the divergence, but firstly, I want to make simple scheme of my program.

Following is my C language code of numerical integration

#include <stdio.h>
#include <math.h>

int main(int argc, char **argv){
int Narray;
int k;
Narray = 2250;
double zeta[Narray];
double dzeta = 0.225/Narray;
double tau[Narray];
zeta[0]=0.9;
tau[0]=0;

for (k=1; k<Narray-1 ; k++){
    zeta[k]=zeta[k-1]+dzeta;
    tau[k]=tau[k-1]+dzeta*zeta[k]/sqrt(0.987654*(zeta[k]-0.9)*(9/8-zeta[k]));
    printf("zeta = %lf tau = %lf \n", zeta[k], tau[k]);
    }
return 0;
}

However, when I compile the code in ubuntu, NaN appears as result...

Also, datas were different from the calculation by Wolframalpha.

( I've sampled few points and compared with Wolfram alpha. )

enter image description here

I suppose problem occurs at the equation of zeta... How can I fix this problem?

$\endgroup$
  • 4
    $\begingroup$ Haven't checked the rest but 9/8 is an integer expression and so returns an integer which will be 1. Try 9.0/8.0, and also understand why this is important. $\endgroup$ – Ian Bush May 20 at 19:03
  • $\begingroup$ Thank you! I forgot the basic concept that what I usually say 9/8 is not the same to computer... $\endgroup$ – user501175 May 20 at 23:47
  • $\begingroup$ NaN disappeared and What's left is just taming improper integration over 0.9 to 0.9+dzeta. And I will try this one myself . Thank you again! $\endgroup$ – user501175 May 20 at 23:50
  • $\begingroup$ @IanBush if you write your comment as answer user501175 can accept it. $\endgroup$ – Mauro Vanzetto May 22 at 10:51
1
$\begingroup$

Haven't checked the rest but 9/8 is an integer expression and so returns an integer which will be 1. Try 9.0/8.0, and also understand why this is important.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.