imag

imag(z)

Return the imaginary part of the complex number z

Examples

The imag function in Julia returns the imaginary part of a complex number z.

julia> imag(3 + 4im)
4

julia> imag(-2 - 5im)
-5

Here are some common examples of using the imag function:

  1. Extract the imaginary part of a complex number:

    julia> z = 2 + 3im;
    julia> imag(z)
    3

    In this example, the imag function is used to extract the imaginary part of the complex number z, which is 3.

  2. Calculate the imaginary part of an expression:

    julia> imag((2 + 3im) * (4 - 2im))
    -10

    The imag function can be used to calculate the imaginary part of an expression. In this case, it calculates the imaginary part of (2 + 3im) * (4 - 2im), which is -10.

  3. Handle purely real numbers:
    julia> imag(5)
    0

    If a purely real number is provided as input, the imag function will return 0.

It's important to note that the imag function only works with complex numbers, and attempting to use it with non-complex numbers will result in an error.

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
Details

Checking you are not a robot: