real
real(z)
Return the real part of the complex number z
Examples
In the Julia programming language, the function real(z)
Return the real part of the complex number z
.
julia> z = 5 + 3im;
julia> real(z)
5
Provide common examples of its use. If there are any common mistakes users make, add an example.
-
Get the real part of a complex number:
julia> z = 2 + 4im; julia> real(z) 2
This example retrieves the real part of the complex number
z
. -
Handle pure real numbers:
julia> x = 7; julia> real(x) 7
When the input is a pure real number, the function returns the same number.
- Handle pure imaginary numbers:
julia> y = 6im; julia> real(y) 0
For pure imaginary numbers, the real part is always 0.
Common mistake example:
julia> w = "hello";
julia> real(w)
ERROR: MethodError: no method matching real(::String)
In this example, the input w
is of type String
, which is not supported by the real
function. It's important to ensure that the input is a complex number or a number with a real component before using the real
function.
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.