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:
-
Extract the imaginary part of a complex number:
julia> z = 2 + 3im; julia> imag(z) 3In this example, the
imagfunction is used to extract the imaginary part of the complex numberz, which is 3. -
Calculate the imaginary part of an expression:
julia> imag((2 + 3im) * (4 - 2im)) -10The
imagfunction 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. - Handle purely real numbers:
julia> imag(5) 0If a purely real number is provided as input, the
imagfunction 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.