Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Using PDL::GSLSF::GAMMA

by wannymahoots (Novice)
on Aug 09, 2012 at 11:14 UTC ( #986493=perlquestion: print w/ replies, xml ) Need Help??
wannymahoots has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to get the perl module PDL::GSLSF::GAMMA working but am having some difficulty. As I understand it, the function "gsl_sf_gamma" should return the gamma function "Gamma(x)". For example, in R:
> gamma(0.4) [1] 2.21816
However, I can't seem to replicate this using PDL:
#!/usr/bin/perl use PDL; use PDL::GSLSF::GAMMA; my $out = gsl_sf_gamma(0.4); print "$out\n";
Output is "1.63493983016443e-14". I'm clearly doing something wrong, please excuse my ignorance. Any help greatly appreciated.

Comment on Using PDL::GSLSF::GAMMA
Select or Download Code
Re: Using PDL::GSLSF::GAMMA
by Khen1950fx (Canon) on Aug 09, 2012 at 14:47 UTC
    Try this:
    #!/usr/bin/perl -l BEGIN { $| = 1; $^W = 1; } use autodie; use PDL::LiteF; use common::sense; BEGIN { use PDL::Config; if ( $PDL::Config{'WITH_GSL'} ) { eval " use PDL::GSLSF::GAMMA "; unless ($@) { return; } else { print "Houston, we have a problem: $!"; } } } my $num = 0.4; my ($f, $e) = gsl_sf_gamma($num); print $f;
Re: Using PDL::GSLSF::GAMMA
by syphilis (Canon) on Aug 09, 2012 at 14:50 UTC
    I get the same (wrong) result as you.
    Either there's a bug in the implementation, or there's a bug in the documentation. Either way, unless someone here comes up with a better idea, I'd report it to the pdl mailing list.

    Another option would be to submit a bug report to the PDL bug tracker on Sourceforge ... if your browser is up to handling something as shitful as Sourceforge and you can find the PDL bug tracker. (Sorry, I don't even have a link.)

    Math::GSL seems to get it right:
    C:\>perl -MMath::GSL::SF -e "print Math::GSL::SF::gsl_sf_gamma(0.4)" 2.21815954375769 C:\>
    I guess that means the error is in the PDL implementation.

    UPDATE: Khen1950fx's approach seems to work ok. But where is this documented ?

    Cheers,
    Rob
Re: Using PDL::GSLSF::GAMMA
by Anonymous Monk on Aug 09, 2012 at 15:08 UTC
    Thanks! The reply by Khen1950fx led me to conclude that this works - the only difference being the presence of round brackets...
    #!/usr/bin/perl use PDL; use PDL::GSLSF::GAMMA; my ($out) = gsl_sf_gamma(0.4); print "$out\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://986493]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-09-23 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls