---
name: "Math::GSL::Complex"
section: "3pm"
platform: "linux"
package: "libmath-gsl-perl"
version: "0.45-2+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Math::GSL::Complex"
---

# Math::GSL::Complex(3pm)

Complex Numbers

### copy()

Returns a copy of the Complex number, which resides at a different location in memory.

```
    my $z    = Math::GSL::Complex->new([10,5]);
    my $copy = $z->copy;
```

## NAME

Math::GSL::Complex - Complex Numbers

## SYNOPSIS

```
    use Math::GSL::Complex qw/:all/;
    my $complex = Math::GSL::Complex->new([3,2]); # creates a complex number 3+2*i
    my $real = $complex->real;                    # returns the real part
    my $imag = $complex->imag;                    # returns the imaginary part
    $complex->gsl_set_real(5);                    # changes the real part to 5
    $complex->gsl_set_imag(4);                    # changes the imaginary part to 4
    $complex->gsl_set_complex(7,6);               # changes it to 7 + 6*i
    ($real, $imag) = $complex->parts;             # get both at once
```

## DESCRIPTION

Here is a list of all the functions included in this module :

- gsl\_complex\_arg($z)

  Return the argument of the complex number `$z`

- gsl\_complex\_abs($z)

  Return \|$z\|, the magnitude of the complex number `$z`

- "gsl\_complex\_rect($x,$y)"

  Create a complex number in cartesian form `$x` + `$y`\*i

- "gsl\_complex\_polar($r,$theta)"

  Create a complex number in polar form `$r`\*exp(i\*$theta)

- gsl\_complex\_abs2($z)

  Return \|$z\|^2, the squared magnitude of the complex number `$z`

- gsl\_complex\_logabs($z)

  Return log(\|$z\|), the natural logarithm of the magnitude of the complex number `$z`

- "gsl\_complex\_add($c1, $c2)"

  Return a complex number which is the sum of the complex numbers `$c1` and `$c2`

- "gsl\_complex\_sub($c1, $c2)"

  Return a complex number which is the difference between `$c1` and `$c2` ($c1 - `$c2`)

- "gsl\_complex\_mul($c1, $c2)"

  Return a complex number which is the product of the complex numbers `$c1` and `$c2`

- "gsl\_complex\_div($c1, $c2)"

  Return a complex number which is the quotient of the complex numbers `$c1` and `$c2` ($c1 / `$c2`)

- "gsl\_complex\_add\_real($c, $x)"

  Return the sum of the complex number `$c` and the real number `$x`

- "gsl\_complex\_sub\_real($c, $x)"

  Return the difference of the complex number `$c` and the real number `$x`

- "gsl\_complex\_mul\_real($c, $x)"

  Return the product of the complex number `$c` and the real number `$x`

- "gsl\_complex\_div\_real($c, $x)"

  Return the quotient of the complex number `$c` and the real number `$x`

- "gsl\_complex\_add\_imag($c, $y)"

  Return sum of the complex number `$c` and the imaginary number i\*$x

- "gsl\_complex\_sub\_imag($c, $y)"

  Return the diffrence of the complex number `$c` and the imaginary number i\*$x

- "gsl\_complex\_mul\_imag($c, $y)"

  Return the product of the complex number `$c` and the imaginary number i\*$x

- "gsl\_complex\_div\_imag($c, $y)"

  Return the quotient of the complex number `$c` and the imaginary number i\*$x

- gsl\_complex\_conjugate($c)

  Return the conjugate of the of the complex number `$c` (x - i\*y)

- gsl\_complex\_inverse($c)

  Return the inverse, or reciprocal of the complex number `$c` (1/$c)

- gsl\_complex\_negative($c)

  Return the negative of the complex number `$c` (-x -i\*y)

- gsl\_complex\_sqrt($c)

  Return the square root of the complex number `$c`

- gsl\_complex\_sqrt\_real($x)

  Return the complex square root of the real number `$x`, where `$x` may be negative

- "gsl\_complex\_pow($c1, $c2)"

  Return the complex number `$c1` raised to the complex power `$c2`

- "gsl\_complex\_pow\_real($c, $x)"

  Return the complex number raised to the real power `$x`

- gsl\_complex\_exp($c)

  Return the complex exponential of the complex number `$c`

- gsl\_complex\_log($c)

  Return the complex natural logarithm (base e) of the complex number `$c`

- gsl\_complex\_log10($c)

  Return the complex base-10 logarithm of the complex number `$c`

- "gsl\_complex\_log\_b($c, $b)"

  Return the complex base-$b of the complex number `$c`

- gsl\_complex\_sin($c)

  Return the complex sine of the complex number `$c`

- gsl\_complex\_cos($c)

  Return the complex cosine of the complex number `$c`

- gsl\_complex\_sec($c)

  Return the complex secant of the complex number `$c`

- gsl\_complex\_csc($c)

  Return the complex cosecant of the complex number `$c`

- gsl\_complex\_tan($c)

  Return the complex tangent of the complex number `$c`

- gsl\_complex\_cot($c)

  Return the complex cotangent of the complex number `$c`

- gsl\_complex\_arcsin($c)

  Return the complex arcsine of the complex number `$c`

- gsl\_complex\_arcsin\_real($x)

  Return the complex arcsine of the real number `$x`

- gsl\_complex\_arccos($c)

  Return the complex arccosine of the complex number `$c`

- gsl\_complex\_arccos\_real($x)

  Return the complex arccosine of the real number `$x`

- gsl\_complex\_arcsec($c)

  Return the complex arcsecant of the complex number `$c`

- gsl\_complex\_arcsec\_real($x)

  Return the complex arcsecant of the real number `$x`

- gsl\_complex\_arccsc($c)

  Return the complex arccosecant of the complex number `$c`

- gsl\_complex\_arccsc\_real($x)

  Return the complex arccosecant of the real number `$x`

- gsl\_complex\_arctan($c)

  Return the complex arctangent of the complex number `$c`

- gsl\_complex\_arccot($c)

  Return the complex arccotangent of the complex number `$c`

- gsl\_complex\_sinh($c)

  Return the complex hyperbolic sine of the complex number `$c`

- gsl\_complex\_cosh($c)

  Return the complex hyperbolic cosine of the complex number `$cy`

- gsl\_complex\_sech($c)

  Return the complex hyperbolic secant of the complex number `$c`

- gsl\_complex\_csch($c)

  Return the complex hyperbolic cosecant of the complex number `$c`

- gsl\_complex\_tanh($c)

  Return the complex hyperbolic tangent of the complex number `$c`

- gsl\_complex\_coth($c)

  Return the complex hyperbolic cotangent of the complex number `$c`

- gsl\_complex\_arcsinh($c)

  Return the complex hyperbolic arcsine of the complex number `$c`

- gsl\_complex\_arccosh($c)

  Return the complex hyperbolic arccosine of the complex number `$c`

- gsl\_complex\_arccosh\_real($x)

  Return the complex hyperbolic arccosine of the real number `$x`

- gsl\_complex\_arcsech($c)

  Return the complex hyperbolic arcsecant of the complex number `$c`

- gsl\_complex\_arccsch($c)

  Return the complex hyperbolic arccosecant of the complex number `$c`

- gsl\_complex\_arctanh($c)

  Return the complex hyperbolic arctangent of the complex number `$c`

- gsl\_complex\_arctanh\_real($x)

  Return the complex hyperbolic arctangent of the real number `$x`

- gsl\_complex\_arccoth($c)

  Return the complex hyperbolic arccotangent of the complex number `$c`

- gsl\_real($z)

  Return the real part of `$z`

- gsl\_imag($z)

  Return the imaginary part of `$z`

- gsl\_parts($z)

  Return a list of the real and imaginary parts of `$z`

- "gsl\_set\_real($z, $x)"

  Sets the real part of `$z` to `$x`

- "gsl\_set\_imag($z, $y)"

  Sets the imaginary part of `$z` to `$y`

- "gsl\_set\_complex($z, $x, $h)"

  Sets the real part of `$z` to `$x` and the imaginary part to `$y`

## EXAMPLES

This code defines `$z` as 6 + 4\*i, takes the complex conjugate of that number, then prints it out.

```
    my $z = gsl_complex_rect(6,4);
    my $y = gsl_complex_conjugate($z);
    my ($real, $imag) = gsl_parts($y);
    print "z = $real + $imag*i\n";
```

This code defines `$z` as 5 + 3\*i, multiplies it by 2 and then prints it out.

```
    my $x = gsl_complex_rect(5,3);
    my $z = gsl_complex_mul_real($x, 2);
    my $real = gsl_real($z);
    my $imag = gsl_imag($z);
    print "Re(\$z) = $real\n";
```

## AUTHORS

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

## COPYRIGHT AND LICENSE

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.
