Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Kronecker delta in Julia?

Tags:

julia

If I have some declared some Points in Julia (p_1,...,p_n). Is there some function or algorithm for kronecker delta (f_i(p_j)=1 if i=j and f_i(p_j)=0 if i != j)

It would be very helpful.

Thank you so much.

like image 219
Tio Miserias Avatar asked Mar 10 '21 20:03

Tio Miserias


1 Answers

If you want a kronecker delta function you can use the ==(x,y) function (as indicated by @mbauman in the comments).

julia> δ(x,y) = ==(x,y)
δ (generic function with 1 method)

julia> δ(1,1)
true

julia> δ(1,2)
false

Note that this returns true or false instead of 1 and 0 but the former are essentially equal to the latter and will behave in the same way, for example ==(1,1) * 2 will give 2. In fact, true isa Integer in Julia.

Another option might be to use I the (lazy) identity matrix built into Julia (LinearAlgebra that is):

julia> using LinearAlgebra

julia> I[1,1]
true

julia> I[1,2]
false
like image 101
carstenbauer Avatar answered Oct 30 '22 13:10

carstenbauer