sunnymathematician
sunnymathematician

Reputation: 31

why julia is generating a complex conjugate upon entering a complex number?

While attempting to enter any complex number in julia console e.g. 2+3im and then pressing the enter key, the output is same as the input, i.e. 2 + 3im. But upon entering the input is in rational form i.e. 1//2+1//5im, and upon pressing the enter key julia outputs 1//2 - 1//5*im. kindly help i am on ubuntu 18.

enter image description here

Upvotes: 3

Views: 78

Answers (2)

Korsbo
Korsbo

Reputation: 724

You need something to indicate that it is the rational number 1//5 which is imaginary and not just the 5.

julia> 1//2 + (1//5)im
1//2 + 1//5*im

julia> 1//2 + 1//5*im
1//2 + 1//5*im

whereas

julia> 1//2 + 1//(5*im)
1//2 - 1//5*im

Upvotes: 5

pfitzseb
pfitzseb

Reputation: 2554

This happens because juxtaposition binds tighter than (almost?) all operators, so your input is parsed as

julia> 1//2 + 1//(5im)
1//2 - 1//5*im

instead of the

julia> 1//2 + (1//5)im
1//2 + 1//5*im

you wanted. That gives the opposite sign from what you expected, because of course im^(-1) == -im.

Upvotes: 6

Related Questions