Math::GSL::Complex Functions concerning complex numbers.
use Math::GSL::Complex qw/:all/; my $complex = Math::GSL::Complex->new([3,2]); # creates a complex number 3+2*i my $real = $complex->real; # returns the real value of the complex number my $imag = $complex->imag; # returns the imaginary value of the complex number $complex->gsl_set_real(5); # changes the real value of the complex number to 5 $complex->gsl_set_imag(4); # changes the imaginary value of the complex number to 4 $complex->gsl_set_complex(7,6); # changes the real value of the complex number to 7 and the imaginary value to 6 ($real, $imag) = $complex->parts; # returns the real and imaginary values of the complex number my $abs = gsl_complex_abs2($complex->raw); # the raw method gives access to the underlying gsl_complex structure, it is needed for the functions below.
Here is a list of all the functions included in this module :
gsl_complex_arg($z)
gsl_complex_abs($z)
gsl_complex_rect($x,$y)
gsl_complex_polar($r,$theta)
gsl_complex_abs2($z)
gsl_complex_logabs($z)
gsl_complex_add($c1, $c2)
gsl_complex_sub($c1, $c2)
gsl_complex_mul($c1, $c2)
gsl_complex_div($c1, $c2)
gsl_complex_add_real($c, $x)
gsl_complex_sub_real($c, $x)
gsl_complex_mul_real($c, $x)
gsl_complex_div_real($c, $x)
gsl_complex_add_imag($c, $y)
gsl_complex_sub_imag($c, $y)
gsl_complex_mul_imag($c, $y)
gsl_complex_div_imag($c, $y)
gsl_complex_conjugate($c)
gsl_complex_inverse($c)
gsl_complex_negative($c)
gsl_complex_sqrt($c)
gsl_complex_sqrt_real($x)
gsl_complex_pow($c1, $c2)
gsl_complex_pow_real($c, $x)
gsl_complex_exp($c)
gsl_complex_log($c)
gsl_complex_log10($c)
gsl_complex_log_b($c, $b)
gsl_complex_sin($c)
gsl_complex_cos($c)
gsl_complex_sec($c)
gsl_complex_csc($c)
gsl_complex_tan($c)
gsl_complex_cot($c)
gsl_complex_arcsin($c)
gsl_complex_arcsin_real($x)
gsl_complex_arccos($c)
gsl_complex_arccos_real($x)
gsl_complex_arcsec($c)
gsl_complex_arcsec_real($x)
gsl_complex_arccsc($c)
gsl_complex_arccsc_real($x)
gsl_complex_arctan($c)
gsl_complex_arccot($c)
gsl_complex_sinh($c)
gsl_complex_cosh($c)
gsl_complex_sech($c)
gsl_complex_csch($c)
gsl_complex_tanh($c)
gsl_complex_coth($c)
gsl_complex_arcsinh($c)
gsl_complex_arccosh($c)
gsl_complex_arccosh_real($x)
gsl_complex_arcsech($c)
gsl_complex_arccsch($c)
gsl_complex_arctanh($c)
gsl_complex_arctanh_real($x)
gsl_complex_arccoth($c)
gsl_real($z)
gsl_imag($z)
gsl_parts($z)
gsl_set_real($z, $x)
gsl_set_imag($z, $y)
gsl_set_complex($z, $x, $h)
You have to add the functions you want to use inside the qw /put_funtion_here / with spaces between each function. You can also write use Math::GSL::Complex qw/:all/ to use all avaible functions of the module.
For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/ Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
This code defines $z as 6 + 4*I, takes the complex conjugate of that number, then prints it out.
my $z = gsl_complex_rect(6,4);
my $y = gsl_complex_conjugate($z);
my ($real, $imag) = gsl_parts($y);
print "z = $real + $imag*I\n";
This code defines $z as 5 + 3*I, multiplies it by 2 and then prints it out.
my $x = gsl_complex_rect(5,3);
my $z = gsl_complex_mul_real($x, 2);
my $real = gsl_real($z);
my $imag = gsl_imag($z);
print "Re(\$z) = $real\n";
Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
Copyright (C) 2008 Jonathan Leto and Thierry Moisan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Math::GSL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::GSL
CPAN shell
perl -MCPAN -e shell install Math::GSL
For more information on module installation, please visit the detailed CPAN module installation guide.