Tags: C pointers, Matrix, Memory Managment
A matrix is an ordered array of values arranged in rows and columns. A fundamental operation in matrix algebra is inverse. In an n-by-n square matrix A\, if a unique matrix n-by-n square B\ exists to make *AB = BA = I*****n\ valid, the matrix B\ is called the inverse of A\, denoted by *A*****-1\, where *I*****n\ is an n-by-n identify matrix.
For example, the matrix 𝐴=, its inverse is 𝐴−1=[−211.5−0.5] since
𝐴𝐴−1=[−211.5−0.5]= and 𝐴−1𝐴=[−211.5−0.5]=
Not all square matrices have inverses. A square matrix which has an inverse is called invertible, and a square matrix without an inverse is called singular.
2. Assessment Task
For this assignment, all values are integer. Design, construct and test a program, which uses arrays having constant dimensions, to perform the following sequence of activity:
a) Prompt for the dimension of the square matrix, which may be no bigger than five in either dimension. Read the elements by row, one row per line of input. Test to see if the matrix is invertible. If the matrix is not invertible, print the standard message (below) on a line by itself, in exactly the format shown and terminate execution.
The matrix is singular
b) Otherwise determine the inverse for the input matrix with four decimal places.
3. Examples of Input/Output
Enter the dimension of the square matrix: 2
Now enter values 2 rows by 2 columns
The inverse of the matrix is:
4. Observations On The Task
You do not always have to use the whole of each array in your program. Proper use of pointers and functions, along with testing of each function individually (in its own main( ) test program) before integration into the complete program, will assist in ensuring correct operation, as well as giving a readable (maintainable) program with a clear modular structure. Your program should follow exactly the format of input and output described and illustrated in the examples. It should check that input data has right format and output date present right format correctly, but must not try to engage in an interactive dialogue. This is not an exercise in human computer interaction, we just want to read in sensible "question" data and detect typing mistakes or other rubbish which might cause the program to crash or produce rubbish on the output. Consider very carefully the range of input values which are acceptable and do not needlessly reject any input which could give a valid product. Careful analysis of
the problem specification, before attempting to implement a solution, is a vital stage in any engineering task. Although a good specification will cover all significant possibilities, it will not usually list them all explicitly (there would be far too many). Part of your design task is to analyse the specification, and by reasoning (ask yourself questions and use elements of the specification to justify your answers) develop a full understanding of the problem and its boundaries.