Math::...ration(3pm)

πŸ’– NAME πŸ’–

Math::GSL::Integration β€” bestie, this is the module for doing numerical integration (quadrature) of a function in one dimension. In 3pm Perl-doc land, obviously. πŸ‘‘


✨ SYNOPSIS ✨

Okay so here's the vibe, literally the whole thing in code:

use Math::GSL::Integration qw /:all/;

my $function = sub { $_[0]**2 } ;
my ($lower, $upper ) = (0,1);
my ($relerr,$abserr) = (0,1e-7);

my ($status, $result, $abserr, $num_evals) = gsl_integration_qng ( $function,
                                                $lower, $upper, $relerr, $abserr
                                             );

That's it. That's the girl. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So like, this module lets you numerically integrate a Perl subroutine. But here's the tea: which quadrature routine you pick fully depends on what your function is giving. Is it smooth? Does it have singularities? Is your range finite, infinite, or semi-infinite? You gotta match the routine to your needs, no cap. 🌸

  • gsl_integration_workspace_alloc($n) β€” allocates a workspace big enough to hold $n double precision intervals, plus their integration results and error estimates. It's giving "I brought enough room for everybody." πŸ’…
  • gsl_integration_workspace_free($w) β€” frees the memory associated with the workspace $w. Release her, she's done. πŸ•ŠοΈ
  • gsl_integration_qaws_table_alloc($alpha, $beta, $mu, $nu) β€” allocates space for a gsl_integration_qaws_table struct describing a singular weight function W(x) with the parameters ($alpha, $beta, $mu, $nu), where W(x) = (x-a)^alpha (b-x)^beta log^mu (x-a) log^nu (b-x). Constraints bestie, listen up: $alpha > -1, $beta > -1, and $mu = 0, 1, $nu = 0, 1. Depending on $mu and $nu, the weight function takes four different forms:
     W(x) = (x-a)^alpha (b-x)^beta                   (mu = 0, nu = 0)
     W(x) = (x-a)^alpha (b-x)^beta log(x-a)          (mu = 1, nu = 0)
     W(x) = (x-a)^alpha (b-x)^beta log(b-x)          (mu = 0, nu = 1)
     W(x) = (x-a)^alpha (b-x)^beta log(x-a) log(b-x) (mu = 1, nu = 1)

The singular points (a,b) don't even have to be specified until the integral is computed β€” and when they are, they're the endpoints of the integration range. The function returns a pointer to the newly allocated table gsl_integration_qaws_table if no errors were detected, and 0 if something went wrong. 😭

  • gsl_integration_qaws_table_set($t, $alpha, $beta, $mu, $nu) β€” this one modifies the parameters ($alpha, $beta, $mu, $nu) of an existing gsl_integration_qaws_table struct $t. Glow-up, not rebuild. ✨
  • gsl_integration_qaws_table_free($t) β€” frees all the memory associated with the gsl_integration_qaws_table struct $t. 🧚
  • gsl_integration_qawo_table_alloc($omega, $L, $sine, $n) β€” (the page lists her, she's here, that's the whole description.) πŸ’€
  • gsl_integration_qawo_table_set($t, $omega, $L, $sine, $n) β€” changes the parameters omega, L and sine of the existing workspace $t. 🫢
  • gsl_integration_qawo_table_set_length($t, $L) β€” lets you change the length parameter $L of the workspace $t. Just the length. Nothing else. Respect her boundaries. 🌈
  • gsl_integration_qawo_table_free($t) β€” frees all the memory associated with the workspace $t. πŸŽ€
  • gsl_integration_qk15($function,$a,$b,$resabs,$resasc) β€” listed, no description given. She's mysterious. πŸ¦‹
  • gsl_integration_qk21($function,$a,$b,$resabs,$resasc) β€” same deal, no description. πŸ™ˆ
  • gsl_integration_qk31($function,$a,$b,$resabs,$resasc) β€” yeah, still no description. πŸ’…
  • gsl_integration_qk41($function,$a,$b,$resabs,$resasc) β€” nope, none here either. ⭐
  • gsl_integration_qk51($function,$a,$b,$resabs,$resasc) β€” she's also just vibing with no notes. πŸ”₯
  • gsl_integration_qk61($function,$a,$b,$resabs,$resasc) β€” the last of the qk girlies with no description. πŸ‘‘
  • gsl_integration_qcheb($function, $a, $b, $cheb12, $cheb24) β€” again, no description on the page. 🌸
  • gsl_integration_qk β€” literally just the name, bestie, that's all the page gives us. πŸ’œ
  • gsl_integration_qng($function,$a,$b,$epsabs,$epsrel,$num_evals) β€” okay so this routine, QNG (Quadrature Non-Adaptive Gaussian), is inexpensive in the sense that it evaluates the function way fewer times than the adaptive routines do. Because of that it needs no workspaces, so it's also more memory efficient. For well-behaved functions (smooth and nonsingular) it should be perfectly fine β€” but for more complicated functions it will not be able to get the required accuracy, or it may just not converge. Know your limits, queen. 😭
  • gsl_integration_qag($function,$a,$b,$epsabs,$epsrel,$limit,$key,$workspace) β€” this routine QAG (Quadrature Adaptive Gaussian) ... and that's where the page stops, trailing dots and all. 🫠
  • gsl_integration_qagi($function,$epsabs,$epsrel,$limit,$workspace) β€” listed, no description. 🌈
  • gsl_integration_qagiu($function,$a,$epsabs,$epsrel,$limit,$workspace) β€” listed, no description. 🧚
  • gsl_integration_qagil($function,$b,$epsabs,$epsrel,$limit,$workspace) β€” listed, no description. πŸŽ€
  • gsl_integration_qags($func,$a,$b,$epsabs,$epsrel,$limit,$workspace) β€” she comes with an example, periodt:
($status, $result, $abserr) = gsl_integration_qags (
                        sub { 1/$_[0]} ,
                        1, 10, 0, 1e-7, 1000,
                        $workspace,
                    );

This function applies the Gauss-Kronrod 21-point integration rule adaptively until an estimate of the integral of $func over ($a,$b) is achieved within the desired absolute and relative error limits, $epsabs and $epsrel. Obsessed with her honestly. πŸ’–

  • gsl_integration_qagp($function, $pts, $npts, $epsbs, $epsrel, $limit, $workspace) β€” listed, no description. (Yes, $epsbs. That's what the page says. I do not make the rules. πŸ’€)
  • gsl_integration_qawc($function, $a, $b, $c, $epsabs, $epsrel, $limit, $workspace) β€” listed, no description. ⭐
  • gsl_integration_qaws($function, $a, $b, $qaws_table, $epsabs, $epsrel, $limit, $workspace) β€” listed, no description. πŸ”₯
  • gsl_integration_qawo($function, $a, $epsabs, $epsrel, $limit, $workspace, $qawo_table) β€” listed, no description. 🌸
  • gsl_integration_qawf($function, $a, $epsabs, $limit, $workspace, $cycle_workspace, $qawo_table) β€” listed, no description. πŸ’œ

This module also includes the following constants, bestie: πŸ’…

  • $GSL_INTEG_COSINE
  • $GSL_INTEG_SINE
  • $GSL_INTEG_GAUSS15
  • $GSL_INTEG_GAUSS21
  • $GSL_INTEG_GAUSS31
  • $GSL_INTEG_GAUSS41
  • $GSL_INTEG_GAUSS51
  • $GSL_INTEG_GAUSS61

The following error constants are part of the Math::GSL::Errno module and can be returned by the gsl_integration_* functions: 🌈

  • $GSL_EMAXITER β€” maximum number of subdivisions was exceeded. Ate too much. 😀
  • $GSL_EROUND β€” cannot reach tolerance because of roundoff error, or roundoff error was detected in the extrapolation table. Rude. 🫠
  • GSL_ESING β€” a non-integrable singularity or other bad integrand behavior was found in the integration interval. Not the vibes. πŸ’€
  • GSL_EDIVERGE β€” the integral is divergent, or too slowly convergent to be integrated numerically. She's not converging, bestie, walk away. 😭

🌟 MORE INFO 🌟

For more information on the functions, we refer you to the GSL official documentation: <http://www.gnu.org/software/gsl/manual/html_node/>


🫢 AUTHORS 🫢

Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>


Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay that's the whole page, you ate that πŸŽ€ this was perl v5.42.3, dated 2026-08-20, and it's the Math::GSL::Integration 3pm page β€” go integrate something slay, ily, bye πŸ’–βœ¨

πŸ“¦ where this page comes from