Return both the real and imaginary parts of the complex number z


In the Julia programming language, the reim(z) function is used to return both the real and imaginary parts of a complex number z. Here are some examples of its usage:

  1. Get real and imaginary parts of a complex number:

    julia> z = 3 + 4im;
    julia> reim(z)
    (3, 4)

    This example returns a tuple (3, 4) where the first element represents the real part and the second element represents the imaginary part of the complex number z.

  2. Handle pure imaginary numbers:

    julia> w = 0 - 2im;
    julia> reim(w)
    (0, -2)

    The reim function works correctly with pure imaginary numbers by returning the real part as 0 and the negative of the imaginary part.

  3. Use with complex number literals:
    julia> reim(1 + 1im)
    (1, 1)

    It can be used directly with complex number literals to obtain the real and imaginary parts.

Common mistake example:

julia> a = 5;
julia> reim(a)
ERROR: MethodError: no method matching reim(::Int64)

In this example, the function reim is mistakenly used with an integer a. It is important to note that reim is specifically designed for complex numbers and cannot be used directly with real numbers or integers.

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: