0

I am new to Mathematica.

I have a lower triangular matrix defined as follow

A = Table[If[i > j, Subscript[a, i, j], 0], {i, s}, {j, s}];

I would like to the lower triangular elements in a list. For example, when s = 2, the list would contain listOfElement = {a_{2,1}} and for s = 3, listOfElement = {a_{2,1},a_{3,1},a_{3,2}}

How can I do this in Mathematica?

Thank you so much in advance

kirikoumath
  • 723
  • 9
  • 20
  • http://mathematica.stackexchange.com/q/99390/5478 – Kuba Sep 20 '16 at 18:26
  • @Kuba extraction of the elements in the linked question seems to be antidiagonal-wise, while OP seems to be interested in "column-wise" extraction... – ewcz Sep 20 '16 at 18:33
  • you can just do this: `Select[Flatten@A, # =!= 0 &]` , assuming there are no explicit zeros in the lower triangular part. – agentp Sep 20 '16 at 19:12

2 Answers2

2

for example this

A = RandomReal[{0, 1}, {3, 3}];
MatrixForm[A]
M = First[Dimensions[A]];
Flatten[A[[# + 1 ;;, #]] & /@ Range[M - 1]]

produces:

(0.586886   0.968229    0.543306
 0.107212   0.0492116   0.103052
 0.0569797  0.429895    0.70289
)

{0.107212,0.0569797,0.429895}
ewcz
  • 12,819
  • 1
  • 25
  • 47
2

You can use Pick together with a selection matrix:

selectionMatrix = LowerTriangularize[ConstantArray[1, {s, s}], -1]

selectionMatrix is now a lower triangular matrix with ones where you want to Pick elements in A. You then get the elements of A like this:

listOfElements = Flatten @ Pick[A, selectionMatrix, 1]

edit: Make sure you define s, of course.

Sjoerd Smit
  • 186
  • 2
  • 7