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

1 Construct two matrices of integers, A with dimensions 3x3 and B with dimension

ID: 3862306 • Letter: 1

Question

1 Construct two matrices of integers, A with dimensions 3x3 and B with dimensions 3x1. Find the product AxB. Also find the product A.*B(2). What happens when you try A.*B or B*A?

2 Get the second row of A. Get the third column of A. Interchange the second and third row of A. Arrange the columns of A in reverse order (col 3, col 2, col 1).

3Construct the 3x3 identity matrix I3. Find I3*A.

4 Find the eigen values and eigen vectors of A.

5 Construct a 3x3 matrix of integers, C. Try A.*C, A*C and C*A. Now do A./C, A/C, AC, CA and inv(A).

Explanation / Answer

The question you have asked include multiple sub questions,

1.)

#include <stdio.h>

int main()
{
int a[10][10], b[10][10], result[10][10], r1, c1, r2, c2, i, j, k;

printf("Enter rows and column for first matrix: ");
scanf("%d %d", &r1, &c1);

printf("Enter rows and column for second matrix: ");
scanf("%d %d",&r2, &c2);

// Column of first matrix should be equal to column of second matrix and
while (c1 != r2)
{
printf("Error! column of first matrix not equal to row of second. ");
printf("Enter rows and column for first matrix: ");
scanf("%d %d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d %d",&r2, &c2);
}

// Storing elements of first matrix.
printf(" Enter elements of matrix 1: ");
for(i=0; i<r1; ++i)
for(j=0; j<c1; ++j)
{
printf("Enter elements a%d%d: ",i+1, j+1);
scanf("%d", &a[i][j]);
}

// Storing elements of second matrix.
printf(" Enter elements of matrix 2: ");
for(i=0; i<r2; ++i)
for(j=0; j<c2; ++j)
{
printf("Enter elements b%d%d: ",i+1, j+1);
scanf("%d",&b[i][j]);
}

// Initializing all elements of result matrix to 0
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
{
result[i][j] = 0;
}

// Multiplying matrices a and b and
// storing result in result matrix
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
for(k=0; k<c1; ++k)
{
result[i][j]+=a[i][k]*b[k][j];
}

// Displaying the result
printf(" Output Matrix: ");
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
{
printf("%d ", result[i][j]);
if(j == c2-1)
printf(" ");
}
return 0;
}

2.)

#include <stdio.h>

void main()
{
static int array1[10][10], array2[10][10];
int i, j, m, n, a, b, c, p, q, r;

printf("Enter the order of the matrix ");
scanf("%d %d", &m, &n);
printf("Enter the co-efficents of the matrix ");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
scanf("%d,", &array1[i][j]);
array2[i][j] = array1[i][j];
}
}
printf("Enter the numbers of two rows to be exchanged ");
scanf("%d %d", &a, &b);
for (i = 0; i < m; ++i)
{
/* first row has index is 0 */
c = array1[a - 1][i];
array1[a - 1][i] = array1[b - 1][i];
array1[b - 1][i] = c;
}
printf("Enter the numbers of two columns to be exchanged ");
scanf("%d %d", &p, &q);
printf("The given matrix is ");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
printf(" %d", array2[i][j]);
printf(" ");
}
for (i = 0; i < n; ++i)
{
/* first column index is 0 */
r = array2[i][p - 1];
array2[i][p - 1] = array2[i][q - 1];
array2[i][q - 1] = r;
}
printf("The matix after interchanging the two rows(in the original matrix) ");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(" %d", array1[i][j]);
}
printf(" ");
}
printf("The matix after interchanging the two columns(in the original matrix) ");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
printf(" %d", array2[i][j]);
printf(" ");
}
}