[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gsl] gsl_sf_beta_inc returns 0.0 all the time
From: |
Alejandro Cámara Iglesias |
Subject: |
Re: [Bug-gsl] gsl_sf_beta_inc returns 0.0 all the time |
Date: |
Thu, 23 Dec 2010 10:34:06 +0100 |
Not an expert, but I have an idea.
Try to create and initialize the from_gsl variable outside the for loop.
Maybe the compiler optimizes the code somehow and executes the printf();
command before initializing the from_gsl variable with the function return
value.
Code:
int main(int argc, char **argv) {
long i;
double x = 0.0;
double a = 0.5;
double b = 0.5;
double from_gsl = 0.0;
for (i=0; i < 10; i++) {
x += 1.0/10.1;
from_gsl = gsl_sf_beta_inc(a,b,x);
printf("a:%f b:%f x:%f betai(a,b,x):%f \n",a,b,x,from_gsl);
}
return 0;
}
This may sound nuts, but I'll try it if you haven't yet.
Good luck!
*Alejandro Cámara*
PhD Student of GICO <http://www.ucm.es/info/giboucm/>
2010/12/22 Andrew Schein <address@hidden>
> I first produced this error on Ubuntu gsl0-dev package 1.13+dfsg-1 on
> Ubuntu
> 10.04 (x86_64), but then downloaded gsl-1.13.tar.gz and compiled from
> source
> (same machine).
>
> Attached is a short program that attempts to reproduce a portion of the
> incomplete beta curve for comparison against a plot shown in Numerical
> Recipes in C++. The numerical recipes plot varies x between (0,1) while
> setting a=b=0.5.
>
> #include <stdio.h>
> #include <gsl/gsl_rng.h>
>
> int main(int argc, char **argv) {
> long i;
> double x = 0.0;
> double a = 0.5;
> double b = 0.5;
> for (i=0; i < 10; i++) {
> x += 1.0/10.1;
> double from_gsl = gsl_sf_beta_inc(a,b,x);
> printf("a:%f b:%f x:%f betai(a,b,x):%f \n",a,b,x,from_gsl);
> }
> return 0;
> }
>
> The output is:
>
> $ ./test_betai
> a:0.500000 b:0.500000 x:0.099010 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.198020 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.297030 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.396040 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.495050 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.594059 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.693069 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.792079 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.891089 betai(a,b,x):0.000000
> a:0.500000 b:0.500000 x:0.990099 betai(a,b,x):0.000000
> $
>
> Thanks,
>
> Andy
>
> --
> Andrew I. Schein
> www.andrewschein.com
> _______________________________________________
> Bug-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-gsl
>