Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

code: #include <stdio.h> #include <stdlib.h> #define ROWS 3 #define COLS 3 void

ID: 3573009 • Letter: C

Question

code:

#include <stdio.h>
#include <stdlib.h>
#define ROWS 3
#define COLS 3
void display(double[ROWS][COLS]);

int main(){
double mat[ROWS][COLS] = { {1./2, 1, 0},
{0, 2./3, 0},
{-1./2, -1, 2./3} };

display(mat);
return 0;
}
void display(double nums[][COLS]) {

//problem with declaring array subscripts with double, so changed to int
int rowNum, colNum;
for (rowNum = 0.; rowNum < ROWS; rowNum++)
{
for (colNum = 0.; colNum < COLS; colNum++)
printf("%1.1f ", nums[rowNum][colNum]);
printf(" ");
}
}

Lab 7 An iterative method for computing the inverse of a matrix A is given by Al-I B +B? B3 where is the identity matrix and B I-A. 172 1 0 Compute the inverse of A o 23 0 Using the method on the top and stop B20 in the expansion for At. Check result by computing A A Hint: This method is only for special type matrix which has eigenvalue 1. It is NOT for all other kind matrix. This lab has no input, give two output, one is inverse A the other one is the result of A A Remark: There is NO input for this assignment and your output MUST similar to the following! Turbo inuA 1.88 0.88 8.00 3.88 1.58 8.00 8.08 1.88 8.00 -8.88 8-8 a 1-aa- 1.50 0.88 1.58

Explanation / Answer

*********************************program.cpp*************************************************

#include <stdio.h>
#include <stdlib.h>
#define ROWS 3
#define COLS 3
void display(double[ROWS][COLS]);
int main(){
double mat[ROWS][COLS] = { {1./2, 1, 0},
{0, 2./3, 0},
{-1./2, -1, 2./3} };
display(mat);
return 0;
}


void display(double mat[][COLS]) {
   float determinant;
   int i,j;
   for(i=0;i<3;i++)
determinant = determinant + (mat[0][i]*(mat[1][(i+1)%3]*mat[2][(i+2)%3] - mat[1][(i+2)%3]*mat[2][(i+1)%3]));

printf(" Inverse of matrix is: ");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
printf("%.2f ",((mat[(i+1)%3][(j+1)%3] * mat[(i+2)%3][(j+2)%3]) - (mat[(i+1)%3][(j+2)%3]*mat[(i+2)%3][(j+1)%3]))/ determinant);
printf(" ");
}
}

*********************************output********************************************************************


Inverse of matrix is:

2.00 -0.00 1.50
-3.00 1.50 0.00
0.00 0.00 1.50

--------------------------------