@@ -320,44 +320,13 @@ function Base.replace_in_print_matrix(A::SymTridiagonal, i::Integer, j::Integer,
320320 i== j- 1 || i== j|| i== j+ 1 ? s : Base. replace_with_centered_mark (s)
321321end
322322
323- # Implements the inverse using the recurrence relation between principal minors
323+ # Implements the determinant using principal minors
324324# a, b, c are assumed to be the subdiagonal, diagonal, and superdiagonal of
325325# a tridiagonal matrix.
326326# Reference:
327327# R. Usmani, "Inversion of a tridiagonal Jacobi matrix",
328328# Linear Algebra and its Applications 212-213 (1994), pp.413-414
329329# doi:10.1016/0024-3795(94)90414-6
330- function inv_usmani (a:: V , b:: V , c:: V ) where {T,V<: AbstractVector{T} }
331- @assert ! has_offset_axes (a, b, c)
332- n = length (b)
333- θ = zeros (T, n+ 1 ) # principal minors of A
334- θ[1 ] = 1
335- n>= 1 && (θ[2 ] = b[1 ])
336- for i= 2 : n
337- θ[i+ 1 ] = b[i]* θ[i]- a[i- 1 ]* c[i- 1 ]* θ[i- 1 ]
338- end
339- φ = zeros (T, n+ 1 )
340- φ[n+ 1 ] = 1
341- n>= 1 && (φ[n] = b[n])
342- for i= n- 1 : - 1 : 1
343- φ[i] = b[i]* φ[i+ 1 ]- a[i]* c[i]* φ[i+ 2 ]
344- end
345- α = Matrix {T} (undef, n, n)
346- for i= 1 : n, j= 1 : n
347- sign = (i+ j)% 2 == 0 ? (+ ) : (- )
348- if i< j
349- α[i,j]= (sign)(prod (c[i: j- 1 ]))* θ[i]* φ[j+ 1 ]/ θ[n+ 1 ]
350- elseif i== j
351- α[i,i]= θ[i]* φ[i+ 1 ]/ θ[n+ 1 ]
352- else # i>j
353- α[i,j]= (sign)(prod (a[j: i- 1 ]))* θ[j]* φ[i+ 1 ]/ θ[n+ 1 ]
354- end
355- end
356- α
357- end
358-
359- # Implements the determinant using principal minors
360- # Inputs and reference are as above for inv_usmani()
361330function det_usmani (a:: V , b:: V , c:: V ) where {T,V<: AbstractVector{T} }
362331 @assert ! has_offset_axes (a, b, c)
363332 n = length (b)
@@ -366,13 +335,12 @@ function det_usmani(a::V, b::V, c::V) where {T,V<:AbstractVector{T}}
366335 return θa
367336 end
368337 θb = b[1 ]
369- for i= 2 : n
370- θb, θa = b[i]* θb- a[i- 1 ]* c[i- 1 ]* θa, θb
338+ for i in 2 : n
339+ θb, θa = b[i]* θb - a[i- 1 ]* c[i- 1 ]* θa, θb
371340 end
372341 return θb
373342end
374343
375- inv (A:: SymTridiagonal ) = inv_usmani (A. ev, A. dv, A. ev)
376344det (A:: SymTridiagonal ) = det_usmani (A. ev, A. dv, A. ev)
377345
378346function getindex (A:: SymTridiagonal{T} , i:: Integer , j:: Integer ) where T
651619== (A:: Tridiagonal , B:: SymTridiagonal ) = (A. dl== A. du== B. ev) && (A. d== B. dv)
652620== (A:: SymTridiagonal , B:: Tridiagonal ) = (B. dl== B. du== A. ev) && (B. d== A. dv)
653621
654- inv (A:: Tridiagonal ) = inv_usmani (A. dl, A. d, A. du)
655622det (A:: Tridiagonal ) = det_usmani (A. dl, A. d, A. du)
656623
657624AbstractMatrix {T} (M:: Tridiagonal ) where {T} = Tridiagonal {T} (M)
0 commit comments