Submit a document that details your problem solving approach when finding the in
ID: 3747087 • Letter: S
Question
Submit a document that details your problem solving approach when finding the inverse of a 2x2 matrix. Explain the problem, goal, inputs, assumptions, outputs, formulas, and algorithm you used to solve this problem. Visit the website mathisfun to find out how to invert a matrix.
You will implement your solution as a C program that should:
Include your name in a comment at the beginning
Match the algorithm you described
Compile without warnings nor errors
Ask the user for values of 'a', 'b', 'c', and 'd'
Handle when the matrix is singular
Compute and print the correct inverse
Use proper indentation and alignment
You will also submit your .c file (do not submit project files, .o files, nor .exe files).
Explanation / Answer
I have written the code and it is working perfectely fine. Please give me an upvote.
Problem:- To find the inverse of a 2X2 matrix.
Goal:- Finding the determinant and then the inverse.
Inputs:- Values of variables of the matrix in integer format.
Assumptions:- Not taken.
Output:- Inverse of the matrix in matrix format with values in float type.
Formulas:- Used the formula of determinant and the inverse of a matrix.
Algorithm:- Given below.
#include<stdio.h>
#include<math.h>
int determinant(int a[2][2])
{
int det= a[0][0]*a[1][1] - a[0][1]*a[1][0];
return det;
}
int main()
{
int a[2][2];
printf("Enter the elements of Matrix : ");
int i,j;
for (i = 0;i < 2; i++)
{
for (j = 0;j < 2; j++)
{
scanf("%d", &a[i][j]);
}
}
int d=determinant(a);
if(d==0)
{
printf("Cannot find inverse because the matrix is singular");
return 0;
}
else
{
float temp1=a[0][0]/d;
float temp2=a[1][1]/d;
float temp3=-a[0][1]/d;
float temp4=-a[1][0]/d;
printf("The inverse of the matrix is ");
printf("%0.2f %0.2f ", temp2,temp3);
printf("%0.2f %0.2f ", temp4,temp1);
return 0;
}
}