Hi I'm helping a friend of mine write a program that multiplies two upper triangular matrices without expanding the matrices. When I say without expanding the matrix, I mean without filling the lower part of the upper triangular matrix with zeros (the goal is to conserve space). I'm reading in the matrix from a file which only has the upper triangular values for the matrices with the lower part omitted.
What I'm trying to accomplish is to write a function which given an array and a pair of indices, would return an element that an expanded matrix would have at that location (0 for below-diagonal, and values above-diagonal). I'm thinking of then using the usual matrix multiplication algorithm that uses this function whenever it needs to access an element. I've been working on this for several hours and I can't come up with a way to transform double matrix indices (i,j) (i goes along rows) to single array indices and vice versa (Just as a reminder I'm using a single dimensional array to store the upper triangular matrix). Any help would be greatly appreciated!
j == i
, elements that would be on the main diagonal are at0
,n
,n + (n-1)
,n + (n-1) + (n-2)
and so on (figuring out thei
th element of this sequence is left as an exercise for the reader). Forj > i
, just addj - i
to the result of the previous calculation. – Igor Tandetnik