A 3x3 matrix A is defined as

A= a11 a12 a13
a21 a22 a23
a31 a32 a33

1. Write a program which

a) calculates and prints on the screen the determinant of matrix A, i.e. a scalar det(A) defined as:

det(A) = a11 * a22 * a33 + a13 * a21 * a32 + a12 * a23 * a31 - a13 * a22 * a31 - a12 * a21 * a33 - a11 * a23 * a32

b) calculates the inverse of matrix A (if it exists), which is

A-1 = (1 / det(A)) * BT, if det(A) != 0

where

B= b11 b12 b13
b21 b22 b23
b31 b32 b33

with elements

b11 = a22 * a33 - a23 * a32, b12 = a23 * a31 - a21 * a33, b13 = a21 * a32 - a22 * a31,
b21 = a13 * a32 - a12 * a33, b22 = a13 * a33 - a13 * a31, b23 = a12 * a31 - a11 * a32,
b31 = a12 * a23 - a13 * a22, b32 = a13 * a21 - a11 * a23, b33 = a11 * a22 - a12 * a21

The matrix BT

B= b11 b12 b13 = b11 b21 b31
b21 b22 b23 b12 b22 b32
b31 b32 b33 b13 b23 b33

is the transpose of the matrix B. Note that the product of a scalar "a" and some matrix D is a matrix

a * D = a * d11 d12 d13 = a * d11 a * d12 a * d13
d21 d22 d23 a * d21 a * d22 a * d23
d31 d32 d33 a * d31 a * d32 a * d33

Note, that if , the inverse of the matrix A does not exist, and the matrix A is called not invertible or singular or degenerate

c) writes into the file the matrix A-1 (if it exists).

d) checks that the matrix product A-1 * A = I, where

I = 1 0 0
0 1 0
0 0 1

is a 3x3 identity matrix, or unit matrix. Your programme should print on the screen the elements of the matrix A-1 * A. Note that the matrix product of two matrices A and B is a matrix C ( )

C= c11 c12 c13
c21 c22 c23
c31 c32 c33

whose elements are

3
cij= E aij * b kj, i, j, k = 1, 2, 3.
k=1

2. Test the program for

A= 2.0 0 0
0 4.0 0
0 0 6.0

A= 1.0 2.0 3.0
4.0 5.0 6.0
7.0 8.0 9.0

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.