Overload subtraction in Vector
[Math-GSL.git] / Poly.i
blob96bbaf835a277eed91f461f66a7a3020804250e3
1 %module "Math::GSL::Poly"
2 // this brakes stuff
3 // %include "typemaps.i"
4 %include "gsl_typemaps.i"
6 %{
7 #include "gsl/gsl_sys.h"
8 %}
9 %include "gsl/gsl_sys.h"
11 %typemap(in) double * (double dvalue) {
12 SV* tempsv;
13 if (!SvROK($input)) {
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);
21 $1 = &dvalue;
24 #gsl_complex gsl_complex_poly_complex_eval (const gsl_complex c [], const int len, const gsl_complex z);
26 %typemap(argout) gsl_complex {
27 AV* tempav = newAV();
28 double x,y;
29 if (argvi >= items) {
30 EXTEND(sp,1);
32 //fprintf(stderr,"--> %g <--\n", GSL_REAL($1));
33 //fprintf(stderr,"--> %g <--\n", GSL_IMAG($1));
35 $result = sv_newmortal();
37 x = GSL_REAL($1);
38 y = GSL_IMAG($1);
40 /* the next 2 lines blow up
41 sv_setnv($result, x);
42 argvi++;
46 %typemap(argout) double * {
47 SV *tempsv;
48 tempsv = SvRV($input);
49 sv_setnv(tempsv, *$1);
52 %typemap(in) gsl_complex const [] {
53 AV *tempav;
54 I32 len;
55 int i, magic, stuff;
56 double x,y;
57 gsl_complex z;
58 SV **elem, **helem, **real, **imag;
59 HV *hash, *htmp;
60 SV *svtmp, tmp;
61 double result[2];
63 printf("gsl_complex typemap\n");
64 if (!SvROK($input))
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);
71 len = av_len(tempav);
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);
79 if ( magic != 0)
80 croak("FETCH magic failed!\n");
82 printf("magic = %d\n", magic);
83 if( *helem == NULL)
84 croak("Structure does not contain 'dat' element\n");
85 printf("helem is:\n");
86 //Perl_sv_dump(*helem);
87 if( i == 0){
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) );
93 $1[i] = 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"
109 %perlcode %{
111 @EXPORT_OK = qw/
112 gsl_poly_eval
113 gsl_poly_complex_eval
114 gsl_complex_poly_complex_eval
115 gsl_poly_dd_init
116 gsl_poly_dd_eval
117 gsl_poly_dd_taylor
118 gsl_poly_solve_quadratic
119 gsl_poly_complex_solve_quadratic
120 gsl_poly_solve_cubic
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 );
131 __END__
133 =head1 NAME
135 Math::GSL::Poly - Functions for evaluating and solving polynomials
137 =head1 SYNOPSIS
139 use Math::GSL::Poly qw/:all/;
141 =head1 DESCRIPTION
143 Here is a list of all the functions included in this module :
145 =over
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
173 =back
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
180 =head1 EXAMPLES
182 =over 1
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";>
194 =back
196 =head1 AUTHORS
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.
207 =cut