INVERSA POR METODO GAUSS JORDAN
por favor necesito un programa que saque la inversa de una matriz usando el metodo de gauzz jordan.. no importa el tamaño de la matriz.. ayudemen por favor se los ruegooooooooooo
// aqui esta tu programa
// calcula la inversa de una matriz de n*n
// con el metodo gauss jordan
// paso a paso
// espero que te sirva
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
#include <ctype.h>
const max = 15;
typedef float matriz[max][max];
int n;
matriz mat;
char op;
void ingreso()
{
clrscr();
printf("Inversa n");
printf("n ? ");
scanf("%d",&n);
clrscr();
printf("DAtos matriz");
for (int x=0;x< n;x++)
{
for (int y=0;y< n;y++)
{
gotoxy(4+7*y,3+x);
scanf("%f",&mat[x][y]);
if (y==x)
mat[x][y+n]= 1;
else
mat[x][y+n]= 0;
}
}
}
void ver(char signo, int l1,int l2, float c)
{
gotoxy(10,5+n);
textcolor(BLUE);
switch(signo)
{
case '/' :
printf("R %d // %8.2f = R %dn",l1,c,l1);
break;
case '+' :
printf("R %d - %8.2f R %d = R %d n",l1,c,l2,l1);
break;
case '=' :
printf("R %d <===> R %dn",l1,l2);
break;
case '-' :
printf("MATRIZ DEL SISTEMAn");
}
textcolor(RED);
for (int x= 0;x<n;x++)
{
for (int y=0;y<2* n;y++)
{
gotoxy(7*(y+1),10+x);
printf("%5.2f",mat[x][y]);
}
}
gotoxy(10,24);
textcolor(WHITE + BLINK);
printf("PRESIONE CUALQUIER TECLA PARA CONTINUARn");
getch();
}
void cambiar(int &l1,int &l2)
{
for (int y =0;y<=n;y++)
{
float aux = mat[l1][y];
mat[l1][y] = mat[l2][y];
mat[l2][y] = aux;
}
}
void calcular()
{
int x,y,x1,y1;
float c ;
int cont,sepudo;
for (x=0;x<n;x++)
{
cont = 0;
sepudo = 1;
do
{
cont++;
c = mat[x][x];
if (c == 0)
if (cont+x <= n)
{
cambiar(x,x+cont);
ver('=',x,x+cont,1);
c = mat[x][x];
}
else
sepudo = 0;
}while( (c == 0) && sepudo);
if (sepudo)
{
for (y =x;y<2*n;y++)
mat[x][y] = mat[x][y] / c;
ver('/',x,x,c);
for( x1 = x+1;x1<n;x1++)
{
c = mat[x1][x];
for (y1 = x;y1<2*n;y1++)
mat[x1][y1] = mat[x1][y1] - c * mat[x][y1];
ver('+',x1,x,c);
}
for (x1 = x-1;x1>=0;x1--)
{
c = mat[x1][x];
for (y1 = x;y1<n;y1++)
mat[x1][y1] = mat[x1][y1] - c * mat[x][y1];
ver('+',x1,x,c);
}
}
}
if (!sepudo)
{
gotoxy(10,23);
printf("NO TIENE SOLUCION o TIENE INFINITAS SOLUCIONESn");
}
}
void main()
{
do
{
ingreso();
if (n > 0)
{
ver('-',1,1,1);
calcular();
}
gotoxy(10,24);
textcolor(WHITE);
printf("Desea calcular otra inversa (S/N) ");
op = toupper(getch());
}while(op == 'S');
}
// calcula la inversa de una matriz de n*n
// con el metodo gauss jordan
// paso a paso
// espero que te sirva
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
#include <ctype.h>
const max = 15;
typedef float matriz[max][max];
int n;
matriz mat;
char op;
void ingreso()
{
clrscr();
printf("Inversa n");
printf("n ? ");
scanf("%d",&n);
clrscr();
printf("DAtos matriz");
for (int x=0;x< n;x++)
{
for (int y=0;y< n;y++)
{
gotoxy(4+7*y,3+x);
scanf("%f",&mat[x][y]);
if (y==x)
mat[x][y+n]= 1;
else
mat[x][y+n]= 0;
}
}
}
void ver(char signo, int l1,int l2, float c)
{
gotoxy(10,5+n);
textcolor(BLUE);
switch(signo)
{
case '/' :
printf("R %d // %8.2f = R %dn",l1,c,l1);
break;
case '+' :
printf("R %d - %8.2f R %d = R %d n",l1,c,l2,l1);
break;
case '=' :
printf("R %d <===> R %dn",l1,l2);
break;
case '-' :
printf("MATRIZ DEL SISTEMAn");
}
textcolor(RED);
for (int x= 0;x<n;x++)
{
for (int y=0;y<2* n;y++)
{
gotoxy(7*(y+1),10+x);
printf("%5.2f",mat[x][y]);
}
}
gotoxy(10,24);
textcolor(WHITE + BLINK);
printf("PRESIONE CUALQUIER TECLA PARA CONTINUARn");
getch();
}
void cambiar(int &l1,int &l2)
{
for (int y =0;y<=n;y++)
{
float aux = mat[l1][y];
mat[l1][y] = mat[l2][y];
mat[l2][y] = aux;
}
}
void calcular()
{
int x,y,x1,y1;
float c ;
int cont,sepudo;
for (x=0;x<n;x++)
{
cont = 0;
sepudo = 1;
do
{
cont++;
c = mat[x][x];
if (c == 0)
if (cont+x <= n)
{
cambiar(x,x+cont);
ver('=',x,x+cont,1);
c = mat[x][x];
}
else
sepudo = 0;
}while( (c == 0) && sepudo);
if (sepudo)
{
for (y =x;y<2*n;y++)
mat[x][y] = mat[x][y] / c;
ver('/',x,x,c);
for( x1 = x+1;x1<n;x1++)
{
c = mat[x1][x];
for (y1 = x;y1<2*n;y1++)
mat[x1][y1] = mat[x1][y1] - c * mat[x][y1];
ver('+',x1,x,c);
}
for (x1 = x-1;x1>=0;x1--)
{
c = mat[x1][x];
for (y1 = x;y1<n;y1++)
mat[x1][y1] = mat[x1][y1] - c * mat[x][y1];
ver('+',x1,x,c);
}
}
}
if (!sepudo)
{
gotoxy(10,23);
printf("NO TIENE SOLUCION o TIENE INFINITAS SOLUCIONESn");
}
}
void main()
{
do
{
ingreso();
if (n > 0)
{
ver('-',1,1,1);
calcular();
}
gotoxy(10,24);
textcolor(WHITE);
printf("Desea calcular otra inversa (S/N) ");
op = toupper(getch());
}while(op == 'S');
}
