Reputation: 251
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.
Upvotes: 3
Views: 266
Reputation: 69819
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.
Upvotes: 3