How to extract the upper triangular matrix w or w/o diagonal in Chapel

39 Views Asked by At

The best stories start with my matrix A.

var A: [{1..4,1..4}] real = (
  (4, -30, 60, -35),
  (-30, 300, -675, 420),
  (60, -675, 1620, -1050),
  (-35, 420, -1050, 700)
  );

I recall somewhere you can get the upper triangle, but I can't find it in the Chapel docs Can you set it to in/exclude the diagonal?

1

There are 1 best solutions below

1
On BEST ANSWER

Using the LinearAlgebra library:

use LinearAlgebra;

var A: [{1..4,1..4}] real = (
  (4, -30, 60, -35),
  (-30, 300, -675, 420),
  (60, -675, 1620, -1050),
  (-35, 420, -1050, 700)
  );

var upperTriangle = triu(A);

// Confirm it worked
writeln(isTriu(upperTriangle));