Math::...omplex(3pm)

πŸ’– NAME πŸ’–

Math::GSL::VectorComplex β€” Complex Vectors. That's the name, that's the vibe, periodt. ✨

And real talk, when you pull this up in your man viewer the page is titled Math::...omplex(3pm) and it lives in the User Contributed Perl Documentation collection. So if that's the title you came in with, bestie, you are exactly where you need to be. 🫢

✨ SYNOPSIS ✨

Okay so here's the whole energy of this module, look at her go:

use Math::GSL::VectorComplex qw/:all/;
my $vec1 = Math::GSL::VectorComplex->new([1 + 2*i, 7*i, 5, -3 ]);
my $vec2 = $vec1 * 5;
my $vec3 = Math::GSL::Vector>new(10);   # 10 element zero vector
my $vec4 = $vec1 + $vec2;

# set the element at index 1 to -i
# and the element at index 3 to i
$vec3->set([ 1, -i ], [ 9, i ]);

my @vec = $vec2->as_list;               # return elements as Perl list

my $dot_product = $vec1 * $vec2;
my $length      = $vec2->length;
my $first       = $vec1->get(0);

Main character energy, honestly. πŸ’…


πŸ¦‹ Objected Oriented Interface to GSL Math::GSL::VectorComplex πŸ¦‹

This is the part where we meet all the methods one by one. Buckle up, they're all so good.

new()

Creates a new Vector of the given size. πŸŽ€

my $vector = Math::GSL::VectorComplex->new(3);

You can also create and set directly the values of the vector like this :

my $vector = Math::GSL::VectorComplex->new([2,4,1]);

raw()

Hands you the underlying GSL vector object created by SWIG. Lowkey the useful part: it lets you use gsl_vector_* functions that don't have an OO counterpart. 🧚

my $vector    = Math::GSL::VectorComplex->new(3);
my $gsl_vector = $vector->raw;
my $stuff      = gsl_vector_get($gsl_vector, 1);

min()

Returns the minimum value contained in the vector.

my $vector = Math::GSL::VectorComplex->new([2,4,1]);
my $minimum = $vector->min;

max()

Returns the minimum value contained in the vector.

Not me typing "minimum" for the max method β€” that is literally what the page says, I'm just the messenger, fr fr. 😭
my $vector = Math::GSL::VectorComplex->new([2,4,1]);
my $maximum = $vector->max;

length()

Returns the number of elements contained in the vector. Counting queen. πŸ‘‘

my $vector = Math::GSL::VectorComplex->new([2,4,1]);
my $length = $vector->length;

as_list()

Gets the content of a Math::GSL::Vector object as a Perl list.

my $vector = Math::GSL::VectorComplex->new(3);
...
my @values = $vector->as_list;

get()

Gets the value of an of a Math::GSL::Vector object.

my $vector = Math::GSL::VectorComplex->new(3);
...
my @values = $vector->get(2);

You can also enter an array of indices to receive their corresponding values:

my $vector = Math::GSL::VectorComplex->new(3);
...
my @values = $vector->get([0,2]);

reverse()

Returns the a vector with the elements in reversed order. Serving backwards realness. πŸ¦‹

use Math::Complex;
my $v1 = Math::GSL::VectorComplex->new([ 1, 2, 3*i]);
my $v2 = $v1->reverse;

set()

Sets values of an of a Math::GSL::Vector object.

my $vector = Math::GSL::VectorComplex->new(3);
$vector->set([1,2], [8,23]);

This sets the second and third value to 8 and 23.

copy()

Returns a copy of the vector, which has the same length and values but resides at a different location in memory. Same fit, different address, iconic. πŸ’…

my $vector = Math::GSL::VectorComplex->new([10 .. 20]);
my $copy   = $vector->copy;

swap()

Exchanges the values in the vectors $v with $w by copying. Trading places, bestie. πŸ”₯

my $v = Math::GSL::VectorComplex->new([1..5]);
my $w = Math::GSL::VectorComplex->new([3..7]);
$v->swap( $w );

πŸ‘‘ AUTHORS πŸ‘‘

Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>

Give them their flowers. 🌸

Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


And that's the whole page, babe. Courtesy of perl v5.42.3, dated 2026-08-20 β€” go forth and complex-vector responsibly. πŸ’–βœ¨πŸ«Ά

πŸ“¦ where this page comes from