POD for Math::GSL::Test
[Math-GSL.git] / Poly.i
blob8aaa9c705f5c5786cca0585a77924c02ff2a95ae
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;
22 #gsl_complex gsl_complex_poly_complex_eval (const gsl_complex c [], const int len, const gsl_complex z);
24 %typemap(argout) gsl_complex {
25 AV* tempav = newAV();
26 double x,y;
27 if (argvi >= items) {
28 EXTEND(sp,1);
30 //fprintf(stderr,"--> %g <--\n", GSL_REAL($1));
31 //fprintf(stderr,"--> %g <--\n", GSL_IMAG($1));
33 $result = sv_newmortal();
35 x = GSL_REAL($1);
36 y = GSL_IMAG($1);
38 /* the next 2 lines blow up
39 sv_setnv($result, x);
40 argvi++;
44 %typemap(argout) double * {
45 SV *tempsv;
46 tempsv = SvRV($input);
47 sv_setnv(tempsv, *$1);
50 %typemap(in) gsl_complex const [] {
51 AV *tempav;
52 I32 len;
53 int i, magic, stuff;
54 double x,y;
55 gsl_complex z;
56 SV **elem, **helem, **real, **imag;
57 HV *hash, *htmp;
58 SV *svtmp, tmp;
59 double result[2];
61 printf("gsl_complex typemap\n");
62 if (!SvROK($input))
63 croak("Math::GSL : $input is not a reference!");
64 if (SvTYPE(SvRV($input)) != SVt_PVAV)
65 croak("Math::GSL : $input is not an array ref!");
67 z = gsl_complex_rect(0,0);
68 tempav = (AV*)SvRV($input);
69 len = av_len(tempav);
70 $1 = (gsl_complex *) malloc((len+1)*sizeof(gsl_complex));
71 for (i = 0; i <= len; i++) {
72 elem = av_fetch(tempav, i, 0);
74 hash = (HV*) SvRV(*elem);
75 helem = hv_fetch(hash, "dat", 3, 0);
76 magic = mg_get(*helem);
77 if ( magic != 0)
78 croak("FETCH magic failed!\n");
80 printf("magic = %d\n", magic);
81 if( *helem == NULL)
82 croak("Structure does not contain 'dat' element\n");
83 printf("helem is:\n");
84 //Perl_sv_dump(*helem);
85 if( i == 0){
86 svtmp = (SV*)SvRV(*helem);
87 //Perl_sv_dump(svtmp);
89 printf("re z = %f\n", GSL_REAL(z) );
90 printf("im z = %f\n", GSL_IMAG(z) );
91 $1[i] = z;
95 #include "gsl/gsl_nan.h"
96 #include "gsl/gsl_poly.h"
97 #include "gsl/gsl_complex.h"
98 #include "gsl/gsl_complex_math.h"
101 %include "gsl/gsl_nan.h"
102 %include "gsl/gsl_poly.h"
103 %include "gsl/gsl_complex.h"
104 %include "gsl/gsl_complex_math.h"
107 %perlcode %{
109 @EXPORT_OK = qw/
110 gsl_poly_eval
111 gsl_poly_complex_eval
112 gsl_complex_poly_complex_eval
113 gsl_poly_dd_init
114 gsl_poly_dd_eval
115 gsl_poly_dd_taylor
116 gsl_poly_solve_quadratic
117 gsl_poly_complex_solve_quadratic
118 gsl_poly_solve_cubic
119 gsl_poly_complex_solve_cubic
120 gsl_poly_complex_workspace_alloc
121 gsl_poly_complex_workspace_free
122 gsl_poly_complex_solve
123 $GSL_POSZERO $GSL_NEGZERO $GSL_NAN
125 our $GSL_NAN = gsl_nan();
127 %EXPORT_TAGS = ( all => \@EXPORT_OK );
129 __END__
131 =head1 NAME
133 Math::GSL::Poly - Functions for evaluating and solving polynomials
135 =head1 SYNOPSIS
137 use Math::GSL::Poly qw/:all/;
139 =head1 DESCRIPTION
141 Here is a list of all the functions included in this module :
143 =over
145 =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.
147 =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.
149 =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.
151 =item * gsl_poly_dd_init
153 =item * gsl_poly_dd_eval
155 =item * gsl_poly_dd_taylor
157 =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.
159 =item * gsl_poly_complex_solve_quadratic
161 =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.
163 =item * gsl_poly_complex_solve_cubic
165 =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.
167 =item * gsl_poly_complex_workspace_free($w) - This function frees all the memory associated with the workspace w.
169 =item * gsl_poly_complex_solve
171 =back
173 For more informations on the functions, we refer you to the GSL offcial documentation:
174 L<http://www.gnu.org/software/gsl/manual/html_node/>
176 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
178 =head1 EXAMPLES
180 =over 1
182 =item C<use Math::GSL::Poly qw/:all/;>
184 =item C<my ($a,$b,$c) = (1,6,9);>
186 =item C<my ($x0, $x1) = (0,0);>
188 =item C<my $num_roots = gsl_poly_solve_quadratic( $a, $b, $c, \$x0, \$x1);>
190 =item C<print "${a}*x**2 + ${b}*x + $c contains $num_roots roots which are $x0 and $x1. \n";>
192 =back
194 =head1 AUTHORS
196 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
198 =head1 COPYRIGHT AND LICENSE
200 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
202 This program is free software; you can redistribute it and/or modify it
203 under the same terms as Perl itself.
205 =cut