1 %module
"Math::GSL::Poly"
3 // %include
"typemaps.i"
4 %include
"gsl_typemaps.i"
7 #include
"gsl/gsl_sys.h"
9 %include
"gsl/gsl_sys.h"
11 %typemap
(in
) double
* (double dvalue
) {
14 croak
("$input is not a reference!\n");
16 tempsv
= SvRV
($input
);
17 if
((!SvNOK
(tempsv
)) && (!SvIOK(tempsv))) {
18 croak
("$input is not a reference to number!\n");
20 dvalue
= SvNV
(tempsv
);
24 #gsl_complex gsl_complex_poly_complex_eval
(const gsl_complex c
[], const int len
, const gsl_complex z
);
26 %typemap
(argout
) gsl_complex
{
32 //fprintf
(stderr
,"--> %g <--\n", GSL_REAL
($
1));
33 //fprintf
(stderr
,"--> %g <--\n", GSL_IMAG
($
1));
35 $result
= sv_newmortal
();
40 /* the next
2 lines blow up
46 %typemap
(argout
) double
* {
48 tempsv
= SvRV
($input
);
49 sv_setnv
(tempsv
, *$
1);
52 %typemap
(in
) gsl_complex const
[] {
58 SV
**elem
, **helem
, **real
, **imag
;
63 printf
("gsl_complex typemap\n");
65 croak
("Math::GSL : $input is not a reference!");
66 if
(SvTYPE
(SvRV
($input
)) != SVt_PVAV
)
67 croak
("Math::GSL : $input is not an array ref!");
69 z
= gsl_complex_rect
(0,0);
70 tempav
= (AV
*)SvRV
($input
);
72 $
1 = (gsl_complex
*) malloc
((len
+1)*sizeof
(gsl_complex
));
73 for
(i
= 0; i
<= len
; i
++) {
74 elem
= av_fetch
(tempav
, i
, 0);
76 hash
= (HV
*) SvRV
(*elem
);
77 helem
= hv_fetch
(hash
, "dat", 3, 0);
78 magic
= mg_get
(*helem
);
80 croak
("FETCH magic failed!\n");
82 printf
("magic = %d\n", magic
);
84 croak
("Structure does not contain 'dat' element\n");
85 printf
("helem is:\n");
86 //Perl_sv_dump
(*helem
);
88 svtmp
= (SV
*)SvRV
(*helem
);
89 //Perl_sv_dump
(svtmp
);
91 printf
("re z = %f\n", GSL_REAL
(z
) );
92 printf
("im z = %f\n", GSL_IMAG
(z
) );
97 #include
"gsl/gsl_nan.h"
98 #include
"gsl/gsl_poly.h"
99 #include
"gsl/gsl_complex.h"
100 #include
"gsl/gsl_complex_math.h"
103 %include
"gsl/gsl_nan.h"
104 %include
"gsl/gsl_poly.h"
105 %include
"gsl/gsl_complex.h"
106 %include
"gsl/gsl_complex_math.h"
113 gsl_poly_complex_eval
114 gsl_complex_poly_complex_eval
118 gsl_poly_solve_quadratic
119 gsl_poly_complex_solve_quadratic
121 gsl_poly_complex_solve_cubic
122 gsl_poly_complex_workspace_alloc
123 gsl_poly_complex_workspace_free
124 gsl_poly_complex_solve
125 $GSL_POSZERO $GSL_NEGZERO $GSL_NAN
127 our $GSL_NAN
= gsl_nan
();
129 %EXPORT_TAGS
= ( all
=> \@EXPORT_OK
);
135 Math
::GSL
::Poly
- Functions for evaluating and solving polynomials
139 use Math
::GSL
::Poly qw
/:all
/;
143 Here is a list of all the functions included in this module
:
147 =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.
149 =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.
151 =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.
153 =item
* gsl_poly_dd_init
155 =item
* gsl_poly_dd_eval
157 =item
* gsl_poly_dd_taylor
159 =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.
161 =item
* gsl_poly_complex_solve_quadratic
163 =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.
165 =item
* gsl_poly_complex_solve_cubic
167 =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.
169 =item
* gsl_poly_complex_workspace_free
($w
) - This function frees all the memory associated with the workspace w.
171 =item
* gsl_poly_complex_solve
175 For more informations on the functions
, we refer you to the GSL offcial documentation
:
176 L
<http
://www.gnu.org
/software
/gsl
/manual
/html_node
/>
178 Tip
: search on google
: site
:http
://www.gnu.org
/software
/gsl
/manual
/html_node
/ name_of_the_function_you_want
184 =item C
<use Math
::GSL
::Poly qw
/:all
/;>
186 =item C
<my
($a
,$b
,$c
) = (1,6,9);>
188 =item C
<my
($x0
, $x1
) = (0,0);>
190 =item C
<my $num_roots
= gsl_poly_solve_quadratic
( $a
, $b
, $c
, \$x0
, \$x1
);>
192 =item C
<print
"${a}*x**2 + ${b}*x + $c contains $num_roots roots which are $x0 and $x1. \n";>
198 Jonathan Leto
<jonathan@leto.net
> and Thierry Moisan
<thierry.moisan@gmail.com
>
200 =head1 COPYRIGHT
AND LICENSE
202 Copyright
(C
) 2008 Jonathan Leto and Thierry Moisan
204 This program is free software
; you can redistribute it and
/or modify it
205 under the same terms as Perl itself.