100% found this document useful (1 vote)
40 views

Float A Float K Float Num Float F Float Num Float Fac Float R Float A Int I

This program calculates the inverse of a matrix using the method of determinants and cofactors. It prompts the user to input the order and elements of a matrix, calculates the determinant, and if non-zero, calculates the cofactors and inverse of the matrix by taking the transpose of the cofactor matrix and dividing by the determinant. It outputs the determinant, checks for singularity, and displays the inverse matrix if it exists.

Uploaded by

Anna Palilingan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
40 views

Float A Float K Float Num Float F Float Num Float Fac Float R Float A Int I

This program calculates the inverse of a matrix using the method of determinants and cofactors. It prompts the user to input the order and elements of a matrix, calculates the determinant, and if non-zero, calculates the cofactors and inverse of the matrix by taking the transpose of the cofactor matrix and dividing by the determinant. It outputs the determinant, checks for singularity, and displays the inverse matrix if it exists.

Uploaded by

Anna Palilingan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1: #include<stdio.

h>
2: #include<math.h>
3: #include<conio.h>
4:
5:
6: float determinant(float a[25][25],float k);
7: void cofactor(float num[25][25],float f);
8: void transpose(float num[25][25],float fac[25][25],float r);
9: int main()
10: {
11: float a[25][25],k,d;
12: int i,j;
13: printf("----------------Novriyan Masombe/17202109007----------\n");
14: printf("----------------Metode Numerik Matriks Inverse------------------------\n");
15: printf("-------------------------------------------------------------\n");
16: printf("masukkan ordo matriks : ");
17: scanf("%f",&k);
18: printf("masukkan elemen dari matriks %.0fX%.0f \n",k,k);
19: for (i=0;i<k;i++)
20: {
21: for (j=0;j<k;j++)
22: {
23: printf("A(%d,%d)",i+1,j+1);
24: scanf("%f",&a[i][j]);
25: }
26: }
27: d=determinant(a,k);
28: printf("Determinan = %.2f",d);
29: if (d==0)
30: printf("\nInverse matriks tidak temukan\n");
31: else
32: cofactor(a,k);
33: printf("\n\n**** Terima Kasih ****");
34: getch();
35: }
36:
37: /*For calculating Determinant of the Matrix */
38: float determinant(float a[25][25],float k)
39: {
40: float s=1,det=0,b[25][25];
41: int i,j,m,n,c;
42: if (k==1)
43: {
44: return (a[0][0]);
45: }
46: else
47: {
48: det=0;
49: for (c=0;c<k;c++)
50: {
51: m=0;
52: n=0;
53: for (i=0;i<k;i++)
54: {
55: for (j=0;j<k;j++)
56: {
57: b[i][j]=0;
58: if (i != 0 && j != c)
59: {
60: b[m][n]=a[i][j];
61: if (n<(k-2))
62: n++;
63: else
64: {
65: n=0;
66: m++;
67: }
68: }
69: }
70: }
71: det=det + s * (a[0][c] * determinant(b,k-1));
72: s=-1 * s;
73: }
74: }
75:
76: return (det);
77: }
78:
79: void cofactor(float num[25][25],float f)
80: {
81: float b[25][25],fac[25][25];
82: int p,q,m,n,i,j;
83: for (q=0;q<f;q++)
84: {
85: for (p=0;p<f;p++)
86: {
87: m=0;
88: n=0;
89: for (i=0;i<f;i++)
90: {
91: for (j=0;j<f;j++)
92: {
93: if (i != q && j != p)
94: {
95: b[m][n]=num[i][j];
96: if (n<(f-2))
97: n++;
98: else
99: {
100: n=0;
101: m++;
102: }
103: }
104: }
105: }
106: fac[q][p]=pow(-1,q + p) * determinant(b,f-1);
107: }
108: }
109: transpose(num,fac,f);
110: }
111: /*Finding transpose of matrix*/
112: void transpose(float num[25][25],float fac[25][25],float r)
113: {
114: int i,j;
115: float b[25][25],inverse[25][25],d;
116:
117: for (i=0;i<r;i++)
118: {
119: for (j=0;j<r;j++)
120: {
121: b[i][j]=fac[j][i];
122: }
123: }
124: d=determinant(num,r);
125: printf("Determinan = %.2f",d);
126: {
127: for (j=0;j<r;j++)
128: {
129: inverse[i][j]=b[i][j] / d;
130: }
131: }
132: printf("\n\n\nThe inverse of matrix is : \n");
133:
134: for (i=0;i<r;i++)
135: {
136: for (j=0;j<r;j++)
137: {
138: printf("\t%.1f",inverse[i][j]);
139: }
140: printf("\n");
141: }
142: }
143:

You might also like