3

I have functions f1 and f2 returning matrices m1 and m2, which are calculated using Diagonal, Tridiagonal, SymTridiagonal from LinearAlgebra package.

In a new function f3 I try computing

j = m1 - m2*im
m3 = exp(j)

but this gives a Method error on computation unless I use j=Matrix(m1-m2*im), saying that no matching method for exp(::LinearAlgebra.Tridiagonal ...)

My question is how can I do this computation in the most optimal way? I am a total beginner in Julia.

1 Answer 1

3

Unless you have a very special structure of j (i.e. if its exponential is sparse - which is unlikely) the best you can do AFAICT is to use a dense matrix as an input to exp:

m3 = LinearAlgebra.exp!([float(x) for x in Tridiagonal(dl, d, du)])

If you expect m3 to be sparse then I think currently there is no special algorithm implemented for that case in Julia.

Note that I use exp! to do operation in place and use a comprehension to make sure the argument to exp! is dense. As exp! expects LinearAlgebra.BlasFloat (that is Union{Complex{Float32}, Complex{Float64}, Float32, Float64}) I use float to make sure that elements of j are appropriately converted. Note that it might fail if you work with e.g. BigFloat or Float16 values - in this case you have to do an appropriate conversion to the expected types yourself.

Sign up to request clarification or add additional context in comments.

3 Comments

j is a tridiagonal matrix with identically zero diagonal. So I do expect it to be very sparse. It's actually J_- = Jx - i Jy from quantum mechanics. If you have a good suggestion for that it would be very helpful. Meanwhile I will try this.
In this case probably writing a custom exponentiation function taking advantage of this information is probably best.
Indeed, that is what I ended up doing. It turned out to be lot more simple. I had however tried using PyCall to import expm from scipy to do this part but Julia still didn't do it as fast as python. I hope the sparse algorithm gets implemented soon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.