Adding documentation and a few typemaps to Statistics
[Math-GSL.git] / Poly.i
blob6db09883e522c93a0b0af7ca1fb2dd0b643ba324
1 %module "Math::GSL::Poly"
2 %include "gsl_typemaps.i"
4 %{
5 #include "gsl/gsl_sys.h"
6 %}
7 %include "gsl/gsl_sys.h"
9 %typemap(in) double * (double dvalue) {
10 SV* tempsv;
11 if (!SvROK($input)) {
12 croak("$input is not a reference!\n");
14 tempsv = SvRV($input);
15 if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
16 croak("$input is not a reference to number!\n");
18 dvalue = SvNV(tempsv);
19 $1 = &dvalue;
21 %typemap(argout) double * {
22 SV *tempsv;
23 tempsv = SvRV($input);
24 sv_setnv(tempsv, *$1);
27 %typemap(in) gsl_complex const [] {
28 AV *tempav;
29 I32 len;
30 int i, magic, stuff;
31 double x,y;
32 gsl_complex z;
33 SV **elem, **helem, **real, **imag;
34 HV *hash, *htmp;
35 SV *svtmp, tmp;
36 double result[2];
38 printf("gsl_complex typemap\n");
39 if (!SvROK($input))
40 croak("Math::GSL : $input is not a reference!");
41 if (SvTYPE(SvRV($input)) != SVt_PVAV)
42 croak("Math::GSL : $input is not an array ref!");
44 z = gsl_complex_rect(0,0);
45 tempav = (AV*)SvRV($input);
46 len = av_len(tempav);
47 $1 = (gsl_complex *) malloc((len+1)*sizeof(gsl_complex));
48 for (i = 0; i <= len; i++) {
49 elem = av_fetch(tempav, i, 0);
51 hash = (HV*) SvRV(*elem);
52 helem = hv_fetch(hash, "dat", 3, 0);
53 magic = mg_get(*helem);
54 if ( magic != 0)
55 croak("FETCH magic failed!\n");
57 printf("magic = %d\n", magic);
58 if( *helem == NULL)
59 croak("Structure does not contain 'dat' element\n");
60 printf("helem is:\n");
61 //Perl_sv_dump(*helem);
62 if( i == 0){
63 svtmp = (SV*)SvRV(*helem);
64 //Perl_sv_dump(svtmp);
66 printf("re z = %f\n", GSL_REAL(z) );
67 printf("im z = %f\n", GSL_IMAG(z) );
68 $1[i] = z;
72 #include "gsl/gsl_nan.h"
73 #include "gsl/gsl_poly.h"
74 #include "gsl/gsl_complex.h"
75 #include "gsl/gsl_complex_math.h"
78 %include "gsl/gsl_nan.h"
79 %include "gsl/gsl_poly.h"
80 %include "gsl/gsl_complex.h"
81 %include "gsl/gsl_complex_math.h"
84 %perlcode %{
86 @EXPORT_OK = qw/
87 gsl_poly_eval
88 gsl_poly_complex_eval
89 gsl_complex_poly_complex_eval
90 gsl_poly_dd_init
91 gsl_poly_dd_eval
92 gsl_poly_dd_taylor
93 gsl_poly_solve_quadratic
94 gsl_poly_complex_solve_quadratic
95 gsl_poly_solve_cubic
96 gsl_poly_complex_solve_cubic
97 gsl_poly_complex_workspace_alloc
98 gsl_poly_complex_workspace_free
99 gsl_poly_complex_solve
100 $GSL_POSZERO $GSL_NEGZERO $GSL_NAN
102 our $GSL_NAN = q{nan};
104 %EXPORT_TAGS = ( all => \@EXPORT_OK );
106 __END__
108 =head1 NAME
110 Math::GSL::Poly - Functions for evaluating and solving polynomials
112 =head1 SYNOPSIS
114 use Math::GSL::Poly qw/:all/;
116 =head1 DESCRIPTION
118 Here is a list of all the functions included in this module :
120 =over
122 =item * gsl_poly_eval(@values, $length, $x) - This function evaluates a polynomial with real coefficients for the real variable $x. $length is the number of elements inside @values. The function returns a complex number.
124 =item * gsl_poly_complex_eval(@values, $length, $z) - This function evaluates a polynomial with real coefficients for the complex variable $z. $length is the number of elements inside @valuesi. The function returns a complex number.
126 =item * gsl_complex_poly_complex_eval(@values, $length, $z) - This function evaluates a polynomial with real coefficients for the complex variable $z. $length is the number of elements inside @values. $length is the number of elements inside @values. The function returns a complex number.
128 =item * gsl_poly_dd_init
130 =item * gsl_poly_dd_eval
132 =item * gsl_poly_dd_taylor
134 =item * gsl_poly_solve_quadratic( $a, $b, $c, \$x0, \$x1) - find the real roots of the quadratic equation $a*x**2+$b*x+$c = 0, return the number of real root (either zero, one or two) and the real roots are returned by $x0, $x1 and $x2 which are deferenced.
136 =item * gsl_poly_complex_solve_quadratic
138 =item * gsl_poly_solve_cubic($a, $b, $c, \$x0, \$x1, \$x2) - find the real roots of the cubic equation x**3+$a*x**2+$b*x+$c = 0, return the number of real root (either one or three) and the real roots are returned by $x0, $x1 and $x2 which are deferenced.
140 =item * gsl_poly_complex_solve_cubic
142 =item * gsl_poly_complex_workspace_alloc($n) - This function allocates space for a gsl_poly_complex_workspace struct and a workspace suitable for solving a polynomial with $n coefficients using the routine gsl_poly_complex_solve.
144 =item * gsl_poly_complex_workspace_free($w) - This function frees all the memory associated with the workspace w.
146 =item * gsl_poly_complex_solve
148 =back
150 For more informations on the functions, we refer you to the GSL offcial documentation:
151 L<http://www.gnu.org/software/gsl/manual/html_node/>
153 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
155 =head1 EXAMPLES
157 =over 1
159 =item C<use Math::GSL::Poly qw/:all/;>
161 =item C<my ($a,$b,$c) = (1,6,9);>
163 =item C<my ($x0, $x1) = (0,0);>
165 =item C<my $num_roots = gsl_poly_solve_quadratic( $a, $b, $c, \$x0, \$x1);>
167 =item C<print "${a}*x**2 + ${b}*x + $c contains $num_roots roots which are $x0 and $x1. \n";>
169 =back
171 =head1 AUTHORS
173 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
175 =head1 COPYRIGHT AND LICENSE
177 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
179 This program is free software; you can redistribute it and/or modify it
180 under the same terms as Perl itself.
182 =cut