Created
May 24, 2012 17:15
-
-
Save jberger/2782878 to your computer and use it in GitHub Desktop.
Integral equation using PerlGSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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