Академический Документы
Профессиональный Документы
Культура Документы
#include<math.h>
#include<conio.h>
#include <stdio.h>
#include<iostream>
#include<cmath>
int main() {
float matriz[100][100];
float pop[100][100];
float op[100][100];
float res[100][100];
float resultado;
int F, C, n; /* Filas F, Columnas C */
float pMin = 0;
char ans;
if (F!= C) {
cout << "Las dimensiones de la matriz son " << F<< "x" << C<< endl;
cout << “ERROR" << endl << "Presiona alguna tecla para continuar" << endl;
getch();
system("CLS");
} else {
cout << "Las dimensiones de la matriz son " << F << "x" << C << endl;
cout << "Las filas y columnas son Iguales" << endl;
cout << "Presiona una tecla para continuar" << endl;
getch();
system("CLS");
}
}
/* Valores de la matriz */
cout << "Las dimensiones de la matriz son " << F << "x" << C<< endl;
for (int i1 = 0; i1 < F; i1++) {
for (int i2 = 0; i2 < C; i2++) {
cout << "Introduce un numero en la posicion " << i1 + 1 << "," << i2 + 1 << ":" <<
endl;
cin >> matriz[i1][i2];
if (i1 != i2) {
pop[i1][i2 + 1] = matriz[i1][i2];
}
}
}
if (matriz[i1][i2] >= 0) {
cout << " " << "+" << matriz[i1][i2] << "x" << i2 + 1 << " ";
} else {
cout << " " << matriz[i1][i2] << "x" << i2 + 1 << " ";
}
}
}
cout << endl;
}
if (matriz[i1][i2] >= 0) {
cout << " " << "+" << matriz[i1][i2] << "x" << i2 + 1 << " ";
} else {
cout << " " << matriz[i1][i2] << "x" << i2 + 1 << " ";
}
}
}
cout << endl;
}
int Matrizidentidad[100];
float suma[100];
cout << “Se usa la matriz identidad de la matriz recien creada" << endl;
for (int i1 = 0; i1 < F; i1++) {
suma[i1] = 0;
for (int i2 = 0; i2 < C- 1; i2++) {
if (i1 == i2) {
cout << “La posicion " << i1 + 1 << "," << i2 + 1 << ": ";
cout << matriz[i1][i2];
pop[i1][C] = matriz[i1][i2];
cout << endl;
// cout<<pop[i1][0]<<"\t";
// cout<<pop[i1][C]<<endl;
} else {
if (i1 != i2) {
suma[i1] += matriz[i1][i2];
}
}
}
for (int i2 = 0; i2 < C - 1; i2++) {
if (i1 == i2) {
if (suma[i2] > matriz[i1][i2]) { // Si los 3 valores son 1 entonces la matriz es
diagonalmente dominante
id[i1] = 0;
// cout<<endl<<"Identidad "<<id[i1];
} else {
int dom = 0;
for (int i = 0; i < F; i++) {
if (id[i] == 1) {
dom = dom + 1;
}
}
if (dom >= F) {
cout << endl << "La matriz es diagonalmente dominante" << endl;
} else {
if (dom < F) {
cout << endl << "La matriz no es diagonalmente dominante" << endl;
}
}
getch();
system("CLS");
// /* Error minimo */
do {
cout << “¿Deseas ingresar un porcentaje? Si es asi aprieta la tecla S, en caso
contrario la tecla N ” << endl;
cin >> ans;
if ((ans == 'S') || (ans == 's')) {
do {
cout << "Ingresa un porcentaje: " << endl;
cin >> pMin;
if (pMin < 0) {
cout << “ERROR: Ingresa un porcentaje valido" << endl;
cout << "Presiona alguna tecla para continuar" << endl;
getch();
system("CLS");
}
} while (pMin < 0);
} else {
if ((ans == 'N') || (ans == 'n')) {
cout << "No ingresate porcentaje” << endl;
}
if ((ans != 's') && (ans != 's') && (ans != 'N') && (ans != 'n')) {
cout << "Introduce una letra valida" << endl;
getch();
system("CLS");
}
}
} while ((ans != 's') && (ans != 's') && (ans != 'N') && (ans != 'n'));
if (pop[i1][i2] >= 0) {
cout << "-" << pop[i1][i2] << "x" << i2 << " ";
op[i1][i2] = pop[i1][i2];
} else {
cout << "+" << (-1 * pop[i1][i2]) << "x" << i2 << " ";
op[i1][i2] = pop[i1][i2];
}
}
} else {
if (i2 == C) {
cout << ") / " << pop[i1][i2];
op[i1][i2] = pop[i1][i2];
} else {
cout << pop[i1][i2] << " ";
op[i1][i2] = pop[i1][i2];
}
}
}
cout << endl;
}
/* Dependiendo de los valores que tienen las variables, se realizaran las siguientes
operaciones */
int a = 2;
int i = 0, vi = 0;
float resX[100][100];
float errorAprox = pMin + 1, act, ant;
int pos1, pos2;
if (i3 == 0) {
resX[i1][i3] = resX[i1][i3] + (op[i2][i3]);
} else {
if (i3 == C) {
resX[i1][i3] = resX[i1][i3] / op[i2][i3];
pos1 = i2;
pos2 = i3;
} else {
if (i3 != i2) {
if ((i1 == 0) && (i2 == 0)) {
resX[i1][i3] = resX[i1][i3] + (op[i2][i3] * vi);
}
if (i1 >= 1) {
if (i2 >= 0) {
res[i1][i3] = resX[i1][i3] + (op[i2][i3] * resX[pos1][pos2]);
}
}
}
}
}
}
cout << "Resultado x" << i2 + 1 << ": " << resX[i1][i2] << endl;
}
cout << endl;
}
}
}
if (i2 == 0) {
res = res + (op[i1][i2]);
} else {
if (i2 == C) {
res = res / op[i1][i2];
pos1 = i1;
pos2 = i2;
} else {
if (i2 >= 1) {
if (i1 <= 0) {
res = res + (op[i1][i2] * vi);
} else {
if (i1 > 0) {
res = res + (op[i1][i2] * resX[pos1][pos2]);
/* cout<<"i1: "<<i1<<endl;
cout<<"i2: "<<i2<<endl;*/
}
}
}
}
}
}
res[i][i1] = res;
cout << resp[i][i1] << endl;
}
if (i > 0) {
cout << endl << "Iteracion " << i + 1 << endl;
for (int j = 0; j < C; j++) {
anterior = resp[i - 1][j];
actual = resp[i][j];
errorAprox = ((actual - anterior) / actual) * 100;
cout << endl << "Respuesta Actual: " << actual << endl;
cout << endl << "Respuesta anterior: " << anterior << endl;
cout << endl << "Error Aproximado actual: " << errorAprox << endl;
}
} else {
cout << endl << "Iteracion " << i + 1;
cout << endl << "~" << endl;
}
i++;
} while (errorAprox > pMin);
}