Julia-Lang how to solve tridiagonal system

1k views Asked by At

I'm new at Julia-Lang and I'm trying to solve a symmetric tridiagonal system in Julia several times, so I, assemble my matrix as

SymTridiagonal( e ,ones(L-4) )

what changes in my system is the right-hand side. So I tried to use Chris Rackauckas solution on this thread, which I quote:

Just do X=lufact(X) and then X\b

The thing is that when I do that I get

ERROR: LoadError: MethodError: no method matching lufact!(::SymTridiagonal{Float64})

lufact!(!Matched::Union{Base.ReshapedArray{T<:Union{Complex{Float32}, Complex{Float64}, Float32, Float64},2,A,MI}

So my question is: What is the right way to make the imput to lufact! function

1

There are 1 answers

0
fredrikekre On

The default factorization for SymTridiagonal matrices is LDLt (obtained from ldltfact), instead of LU (obtained from lufact). If you just want to solve the system Ax=b where A is a SymTridiagonal it is enough to do

x = A\b

and julia will dispatch to ldltfact to solve the problem. If you want to be explicit about it (or want to use the factorization for something else) you can use

F = ldltfact(A) # or F = factorize(A) which will also return LDLt
x = F\b

If specifically need an LU-factorization you can use

F = lufact(Tridiagonal(A))

as pointed out in the comments, but it is more efficient to use ldltfact in this case.