How to do the complex conjugate of a matrix in Julia

I cannot find the function online. I tried conj(matrix) but that does not work

Strange:

julia> m = rand(Complex128, 3, 3)
3Ă—3 Array{Complex{Float64},2}:
 0.982666+0.280718im    0.81342+0.55867im   0.0734141+0.800991im
 0.545326+0.0841717im  0.933615+0.559221im  0.0828029+0.239306im
  0.55027+0.761457im   0.739435+0.342127im   0.359313+0.111884im

julia> conj(m)
3Ă—3 Array{Complex{Float64},2}:
 0.982666-0.280718im    0.81342-0.55867im   0.0734141-0.800991im
 0.545326-0.0841717im  0.933615-0.559221im  0.0828029-0.239306im
  0.55027-0.761457im   0.739435-0.342127im   0.359313-0.111884im

or

julia> conj.(m)
3Ă—3 Array{Complex{Float64},2}:
 0.982666-0.280718im    0.81342-0.55867im   0.0734141-0.800991im
 0.545326-0.0841717im  0.933615-0.559221im  0.0828029-0.239306im
  0.55027-0.761457im   0.739435-0.342127im   0.359313-0.111884im
1 Like

Maybe the OP is using v0.7 where it’s adjoint? Or on both it’s just matrix'.

Edit: oh wait, do you want the conjugate or each variable? Then broadcast via conj. as @DNF says. But if it’s the matrix conjugate, i.e. the adjoint or conjugate transpose, I’d recommend '.

1 Like

No, unfortunately I am still on v.602

I am very new and this helps with more than just the conjugate, also how to create complex matrices.

So, say I would like to create two 2X2 matrices, one a normal diagonal matrix with complex float point numbers on the diagonal, and one an “opposite” diagonal [0,#;#0].

Would anyone be able to help me with this?

julia> Complex{Float64}[1.0 0.0; 0.0 1.0]
2Ă—2 Array{Complex{Float64},2}:
 1.0+0.0im  0.0+0.0im
 0.0+0.0im  1.0+0.0im
1 Like

conj(matrix) works on 0.7 as well. It is effectively equivalent to conj.(matrix), but the latter has the advantage of fusing with other dot calls.

(The reason conj(array) continues to be defined, despite the existence of conj.(array), is that complex conjugation is a standard, well-defined mathematical operation on any complex vector space, as opposed to a function like sin.(array) that is only defined elementwise in general.)

3 Likes

Like this, maybe

julia> d = diagm(Complex128[1.1, 2.2])
2Ă—2 Array{Complex{Float64},2}:
 1.1+0.0im  0.0+0.0im
 0.0+0.0im  2.2+0.0im

julia> flipdim(d, 2)
2Ă—2 Array{Complex{Float64},2}:
 0.0+0.0im  1.1+0.0im
 2.2+0.0im  0.0+0.0im

julia> flipdim(d, 1)
2Ă—2 Array{Complex{Float64},2}:
 0.0+0.0im  2.2+0.0im
 1.1+0.0im  0.0+0.0im
1 Like

Thank you!