Question: An upper triangular matrix is a special type of matrix where all the values below the main diagonal are 0. In order to save space

An upper triangular matrix is a special type of matrix where all the values below the main diagonal are 0. In order to save space we can store this matrix without the zeros. For example 1 2 3 0 4 5 0 0 6 Would be stored as 1 2 3 4 5 6 We would also like to be able to work with these matrices in their compressed format, again to save space. Write a C++ program called that accepts as arguments two files that contain these compressed upper triangular matrices. The program should multiply the two matrices together and then display the resulting compressed matrix in its compressed form.

The names of the files will be given on the command line

All matrices will be square, ie N X N

All values will be integers

File format:

N (dimension of the matrix)

number1 number2 number3 ...

For help on matrix multiplication see http://www.purplemath.com/modules/mtrxmult.htm.

Restrictions: You cannot expand the compressed matrices to do the multiplication. Again the whole point is to save space.

In the examples on the next page the values are shown on 1 line to save space

Cat mat1.txt 4 1 2 3 17 4 51 25 6 31 9

cat mat2.txt 4 25 73 -4 -17 -99 81 -88 11 12 10

./triMatMult.out mat1.txt mat2.txt

25 -125 191 13 -396 885 510 66 382 90

This is equivalent to doing C = A * B where:

A = 1 2 3 17 0 4 51 25 0 0 6 31 0 0 0 9

B = 25 73 -4 -17 0 -99 81 -88 0 0 11 12 0 0 0 10

C = 25 -125 191 13 0 -396 885 510 0 0 66 382 0 0 0 90

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!