Skip to content

Instantly share code, notes, and snippets.

@jberger
Created May 24, 2012 17:15
Show Gist options
  • Save jberger/2782878 to your computer and use it in GitHub Desktop.
Save jberger/2782878 to your computer and use it in GitHub Desktop.
Integral equation using PerlGSL
#!/usr/bin/env perl
use strict;
use warnings;
use PerlGSL qw/int_1d findroot_1d/;
# _ 2
# / 1 x
# | exp( - -- ) dx = c
#_/ 0 2
# a
# solve for 'a' for a given 'c'
my $c = 0.5;
my $eqn = sub {
my $a = shift;
my $integrand = sub {
my $x = shift;
return exp( - $x**2 / $a**2 );
};
return int_1d( $integrand, 0, 1 ) - $c;
};
my $found = findroot_1d( $eqn, 0.1, 10);
print $found . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment