Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign off-diagonal entries in SymTridiagonal matrix in julia?

The SymTridiagonal data type in Julia is not letting me assign non-diagonal values to anything other than zero. I get this error: ArgumentError: cannot set off-diagonal entry (2, 1). I need to assign non-diagonal values because I am trying to implement the ImplicitSymmetricQRStep algorithm which needs to do that in the process.

like image 227
user15269 Avatar asked Oct 16 '25 15:10

user15269


1 Answers

It is indeed not possible to set the off diagonal values of SymTridiagonal matrix - why this decision was taken I cannot say.

I see now two alternatives:

1) In Julia the fields of a structure are not hidden, so it is possible to change the value that way. This is dangerous though, as the internal structure of that matrix might change in future versions without any warnings. Here is an example of how you would do that:

using LinearAlgebra: SymTridiagonal

a = SymTridiagonal([1 2 0; 2 1 2; 0 2 1)] # 1 on diagonal, 2 on off diagonals
a.ev[1] = 4 # a[1, 2] == 4 and a[2, 1] == 4

2) You could also use the Tridiagonal matrix type, that is also in the LinearAlgebra package; this type allows one to set the off diagonal entries. Then you just have to make sure yourself that you don't violate the symmetric properties of that matrix i.e if you set a[i, j] then you also have to set a[j, i] to the same value.

like image 147
Simon Schoelly Avatar answered Oct 18 '25 19:10

Simon Schoelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!