4 use Math::GSL qw/:all/;
5 use Math::GSL::Complex qw/:all/;
6 use Math::GSL::Errno qw/:all/;
11 gsl_matrix_complex_alloc
12 gsl_matrix_complex_calloc
13 gsl_matrix_complex_alloc_from_block
14 gsl_matrix_complex_alloc_from_matrix
15 gsl_vector_complex_alloc_row_from_matrix
16 gsl_vector_complex_alloc_col_from_matrix
17 gsl_matrix_complex_free
18 gsl_matrix_complex_submatrix
19 gsl_matrix_complex_row
20 gsl_matrix_complex_column
21 gsl_matrix_complex_diagonal
22 gsl_matrix_complex_subdiagonal
23 gsl_matrix_complex_superdiagonal
24 gsl_matrix_complex_subrow
25 gsl_matrix_complex_subcolumn
26 gsl_matrix_complex_view_array
27 gsl_matrix_complex_view_array_with_tda
28 gsl_matrix_complex_view_vector
29 gsl_matrix_complex_view_vector_with_tda
30 gsl_matrix_complex_const_submatrix
31 gsl_matrix_complex_const_row
32 gsl_matrix_complex_const_column
33 gsl_matrix_complex_const_diagonal
34 gsl_matrix_complex_const_subdiagonal
35 gsl_matrix_complex_const_superdiagonal
36 gsl_matrix_complex_const_subrow
37 gsl_matrix_complex_const_subcolumn
38 gsl_matrix_complex_const_view_array
39 gsl_matrix_complex_const_view_array_with_tda
40 gsl_matrix_complex_const_view_vector
41 gsl_matrix_complex_const_view_vector_with_tda
42 gsl_matrix_complex_get
43 gsl_matrix_complex_set
44 gsl_matrix_complex_ptr
45 gsl_matrix_complex_const_ptr
46 gsl_matrix_complex_set_zero
47 gsl_matrix_complex_set_identity
48 gsl_matrix_complex_set_all
49 gsl_matrix_complex_fread
50 gsl_matrix_complex_fwrite
51 gsl_matrix_complex_fscanf
52 gsl_matrix_complex_fprintf
53 gsl_matrix_complex_memcpy
54 gsl_matrix_complex_swap
55 gsl_matrix_complex_swap_rows
56 gsl_matrix_complex_swap_columns
57 gsl_matrix_complex_swap_rowcol
58 gsl_matrix_complex_transpose
59 gsl_matrix_complex_transpose_memcpy
60 gsl_matrix_complex_isnull
61 gsl_matrix_complex_ispos
62 gsl_matrix_complex_isneg
63 gsl_matrix_complex_add
64 gsl_matrix_complex_sub
65 gsl_matrix_complex_mul_elements
66 gsl_matrix_complex_div_elements
67 gsl_matrix_complex_scale
68 gsl_matrix_complex_add_constant
69 gsl_matrix_complex_add_diagonal
70 gsl_matrix_complex_get_row
71 gsl_matrix_complex_get_col
72 gsl_matrix_complex_set_row
73 gsl_matrix_complex_set_col
76 %EXPORT_TAGS = ( all => \@EXPORT_OK , );
80 Math::GSL::MatrixComplex - Complex Matrices
84 use Math::GSL::MatrixComplex qw/:all/;
85 my $matrix1 = Math::GSL::MatrixComplex->new(5,5); # OO interface
86 my $matrix2 = gsl_matrix_complex_alloc(5,5); # standard interface
89 =head1 Objected Oriented Interface to GSL Math::GSL::MatrixComplex
93 Creates a new MatrixComplex object of the given size.
95 my $matrix = Math::GSL::MatrixComplex->new(10,10);
100 my ($class, $rows, $cols) = @_;
103 if ( defined $rows && defined $cols &&
104 $rows > 0 && $cols > 0 &&
105 (int $rows == $rows) && (int $cols == $cols)){
107 $matrix = gsl_matrix_complex_alloc($rows,$cols);
109 croak( __PACKAGE__.'::new($x,$y) - $x and $y must be positive integers');
111 gsl_matrix_complex_set_zero($matrix);
112 $this->{_matrix} = $matrix;
113 ($this->{_rows}, $this->{_cols}) = ($rows,$cols);
118 Get the underlying GSL matrix object created by SWIG, useful for using gsl_matrix_* functions which do not have an OO counterpart.
120 my $matrix = Math::GSL::MatrixComplex->new(3,3);
121 my $gsl_matrix = $matrix->raw;
122 my $stuff = gsl_matrix_complex_get($gsl_matrix, 1, 2);
125 sub raw { (shift)->{_matrix} }
128 Returns the number of rows in the matrix.
130 my $rows = $matrix->rows;
133 sub rows { (shift)->{_rows} }
137 Returns the number of columns in the matrix.
139 my $cols = $matrix->cols;
142 sub cols { (shift)->{_cols} }
146 Get the contents of a Math::GSL::Matrix object as a Perl list.
148 my $matrix = Math::GSL::MatrixComplex->new(3,3);
150 my @matrix = $matrix->as_list;
160 for($line=0; $line<$self->rows; $line++){
162 gsl_matrix_complex_get($self->raw, $line, $_)
163 } (0 .. $self->cols-1 );
171 Returns a row matrix of the row you enter.
173 my $matrix = Math::GSL::MatrixComplex->new(3,3);
175 my $matrix_row = $matrix->row(0);
181 my ($self, $row) = @_;
182 croak (__PACKAGE__.'::$matrix->row($row) - invalid $row value')
183 unless (($row < $self->rows) and $row >= 0);
185 my $rowmat = Math::GSL::MatrixComplex->new(1,$self->cols);
187 for my $n (0 .. $self->cols-1) {
188 gsl_matrix_complex_set( $rowmat->raw, 0, $n,
189 gsl_matrix_complex_get($self->raw, $row, $n)
198 Returns a col matrix of the column you enter.
200 my $matrix = Math::GSL::MatrixComplex->new(3,3);
202 my $matrix_col = $matrix->col(0);
208 my ($self, $col) = @_;
209 croak (__PACKAGE__."::\$matrix->col(\$col) - $col not a valid column")
210 unless ($col < $self->cols and $col >= 0);
212 my $colmat = Math::GSL::MatrixComplex->new($self->rows, 1);
214 map { gsl_matrix_complex_set($colmat->raw, $_, 0,
215 gsl_matrix_complex_get($self->raw, $_, $col),
217 } (0 .. $self->rows-1);
224 Sets a the values of a row with the elements of an array.
226 my $matrix = Math::GSL::MatrixComplex->new(3,3);
227 $matrix->set_row(0, [8, 6, 2]);
229 You can also set multiple rows at once with chained calls:
230 my $matrix = Math::GSL::MatrixComplex->new(3,3);
231 $matrix->set_row(0, [8, 6, 2])
232 ->set_row(1, [2, 4, 1]);
238 my ($self, $row, $values) = @_;
239 my $length = $#$values;
240 die __PACKAGE__.'::set_row($x, $values) - $values must be a nonempty array reference' if $length == -1;
241 die __PACKAGE__.'::set_row($x, $values) - $x must be a valid row number' if ($row < 0 || $row >= $self->rows);
242 die __PACKAGE__.'::set_row($x, $values) - $values must contains the same number of elements as there is columns in the matrix' if($length != $self->cols-1);
243 # $values may have Math::Complex objects
244 @$values = map { Math::GSL::Complex::gsl_complex_rect(Re($_), Im($_)) } @$values;
245 # warn Dumper [ @$values ];
246 map { gsl_matrix_complex_set($self->raw, $row, $_, $values->[$_]) } (0..$length);
252 Sets a the values of a column with the elements of an array.
254 my $matrix = Math::GSL::MatrixComplex->new(3,3);
255 $matrix->set_col(0, [8, 6, 2]);
257 You can also set multiple columns at once with chained calls:
258 my $matrix = Math::GSL::MatrixComplex->new(3,3);
259 $matrix->set_col(0, [8, 6, 2])
260 ->set_col(1, [2, 4, 1]);
266 my ($self, $col, $values) = @_;
267 my $length = $#$values;
268 die __PACKAGE__.'::set_col($x, $values) - $values must be a nonempty array reference' if $length == -1;
269 die __PACKAGE__.'::set_col($x, $values) - $x must be a valid column number' if ($col < 0 || $col >= $self->cols);
270 die __PACKAGE__.'::set_col($x, $values) - $values must contains the same number of elements as there is rowss in the matrix' if($length != $self->rows-1);
271 # $values may have Math::Complex objects
272 @$values = map { gsl_complex_rect(Re($_), Im($_)) } @$values;
273 map { gsl_matrix_complex_set($self->raw, $_, $col, $values->[$_]) } (0..$length);
281 =item C<gsl_matrix_complex_alloc >
283 =item C<gsl_matrix_complex_calloc >
285 =item C<gsl_matrix_complex_alloc_from_block >
287 =item C<gsl_matrix_complex_alloc_from_matrix >
289 =item C<gsl_vector_complex_alloc_row_from_matrix >
291 =item C<gsl_vector_complex_alloc_col_from_matrix >
293 =item C<gsl_matrix_complex_free >
295 =item C<gsl_matrix_complex_submatrix >
297 =item C<gsl_matrix_complex_row >
299 =item C<gsl_matrix_complex_column >
301 =item C<gsl_matrix_complex_diagonal >
303 =item C<gsl_matrix_complex_subdiagonal >
305 =item C<gsl_matrix_complex_superdiagonal >
307 =item C<gsl_matrix_complex_subrow >
309 =item C<gsl_matrix_complex_subcolumn >
311 =item C<gsl_matrix_complex_view_array >
313 =item C<gsl_matrix_complex_view_array_with_tda >
315 =item C<gsl_matrix_complex_view_vector >
317 =item C<gsl_matrix_complex_view_vector_with_tda >
319 =item C<gsl_matrix_complex_const_submatrix >
321 =item C<gsl_matrix_complex_const_row >
323 =item C<gsl_matrix_complex_const_column >
325 =item C<gsl_matrix_complex_const_diagonal >
327 =item C<gsl_matrix_complex_const_subdiagonal >
329 =item C<gsl_matrix_complex_const_superdiagonal >
331 =item C<gsl_matrix_complex_const_subrow >
333 =item C<gsl_matrix_complex_const_subcolumn >
335 =item C<gsl_matrix_complex_const_view_array >
337 =item C<gsl_matrix_complex_const_view_array_with_tda >
339 =item C<gsl_matrix_complex_const_view_vector >
341 =item C<gsl_matrix_complex_const_view_vector_with_tda >
343 =item C<gsl_matrix_complex_get>
345 =item C<gsl_matrix_complex_set>
347 =item C<gsl_matrix_complex_ptr>
349 =item C<gsl_matrix_complex_const_ptr>
351 =item C<gsl_matrix_complex_set_zero >
353 =item C<gsl_matrix_complex_set_identity >
355 =item C<gsl_matrix_complex_set_all >
357 =item C<gsl_matrix_complex_fread >
359 =item C<gsl_matrix_complex_fwrite >
361 =item C<gsl_matrix_complex_fscanf >
363 =item C<gsl_matrix_complex_fprintf >
365 =item C<gsl_matrix_complex_memcpy>
367 =item C<gsl_matrix_complex_swap>
369 =item C<gsl_matrix_complex_swap_rows>
371 =item C<gsl_matrix_complex_swap_columns>
373 =item C<gsl_matrix_complex_swap_rowcol>
375 =item C<gsl_matrix_complex_transpose >
377 =item C<gsl_matrix_complex_transpose_memcpy >
379 =item C<gsl_matrix_complex_isnull >
381 =item C<gsl_matrix_complex_ispos >
383 =item C<gsl_matrix_complex_isneg >
385 =item C<gsl_matrix_complex_add >
387 =item C<gsl_matrix_complex_sub >
389 =item C<gsl_matrix_complex_mul_elements >
391 =item C<gsl_matrix_complex_div_elements >
393 =item C<gsl_matrix_complex_scale >
395 =item C<gsl_matrix_complex_add_constant >
397 =item C<gsl_matrix_complex_add_diagonal >
399 =item C<gsl_matrix_complex_get_row>
401 =item C<gsl_matrix_complex_get_col>
403 =item C<gsl_matrix_complex_set_row>
405 =item C<gsl_matrix_complex_set_col>
409 For more informations on the functions, we refer you to the GSL offcial documentation
410 L<http://www.gnu.org/software/gsl/manual/html_node/>
415 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
417 =head1 COPYRIGHT AND LICENSE
419 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
421 This program is free software; you can redistribute it and/or modify it
422 under the same terms as Perl itself.