-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix Invert Jordan Method.cpp
64 lines (56 loc) · 1.41 KB
/
Matrix Invert Jordan Method.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
Algoritmo: Invertir matrices Método de Jordan
Make by: Marlon A. Espinosa Castañeiras
Universida de Oriente, Santiago de Cuba
21/11/2015
**/
#include <bits/stdc++.h>
using namespace std;
double A[100][100], B[100], X[100], Mik;
int main()
{
int n;
cout<<"Introduzca la cantidad de variables: ";
cin>> n;
cout<<"Introduzca los coeficientes:\n";
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++)
cin>> A[i][j];
A[i][n + i] = 1;///anexando la matriz identidad
}
/**escalonando ambas matrices a la vez**/
for(int k = 1;k <= n;k++){
for(int i = 1; i <= n;i++){
if(i != k){
Mik = A[i][k] / A[k][k];
for(int j = k; j <= 2*n;j++)
A[i][j] = A[i][j] - Mik * A[k][j];
}
}
system("pause");
cout<<"PASO "<<k<<":\n";
for(int i = 1;i <= n;i++){
for(int j = 1;j <= 2 * n;j++)
printf("%.1lf ", A[i][j]);
cout<<endl;
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= 2*n;j++){
A[i][j] = A[i][j] / A[i][i];/// dividiendo todas las filas por su respectivo pivote (A[i][i])
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= 2 * n;j++)
printf("%.1lf ", A[i][j]);
cout<<endl;
}
return 0;
}
/**
4
1 -2 2 -1 0
2 -3 1 1 1
1 -1 2 3 5
2 1 1 -1 3
*/