Академический Документы
Профессиональный Документы
Культура Документы
DE MORELOS.
CENTRO DE INVESTIGACIÓN EN INGENIERÍA Y CIENCIAS APLICADAS.
MAESTRÍA EN SUSTENTABILIDAD ENERGÉTICA.
//cambiar filas
if(k!=ind){
for(int i=0;i<n+1;i++){
aux=M[k][i];
M[k][i]=M[ind][i];
M[ind][i]=aux;
}
}
if(M[k][k]==0){
cout<<"no tiene solucion";
break;
}
Ing. Ángel Sánchez Cruz Dr. Antonio Rodríguez Martínez Métodos numéricos, C++
else{
M[i][j]=M[i][j]+pivote*M[k][j]/M[k][k];
}
}
else{
pivote=M[k][k];
for(int j=k;j<n+1;j++){
M[i][j]=M[i][j]/pivote;
}
}
}
}
}
}
void ingresar_coeficientes(double M[20][20],int n){
cout<<"\nIngrese las ecuaciones para:"<<endl;
for(int i=0;i<n;i++){
cout<<"\t"<<"Fila "<<i+1<<" : "<<endl;
for(int j=0;j<n+1;j++){
cin>>M[i][j];
}
}
}
int main (int argc, char *argv[]) {
int n;
double M[20][20];
cout<<"Ingrese el numero de ecuaciones:";
cin>>n;
ingresar_coeficientes(M,n);
Ing. Ángel Sánchez Cruz Dr. Antonio Rodríguez Martínez Métodos numéricos, C++
cout<<"\nMatriz aumentada:"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n+1;j++){
cout<<M[i][j]<<"\t";
}cout<<endl;
}
cout<<"\nMatriz reducida a ceros:"<<endl;
gauss_jordan(M,n);
for(int i=0;i<n;i++){
for(int j=0;j<n+1;j++){
cout<<M[i][j]<<"\t";
}cout<<endl;
}
cout<<"\nSolucion de incognitas:"<<endl;
for(int i=0;i<n;i++){
cout<<"X"<<i+1<<"="<<M[i][n]<<"\t";
}cout<<endl;
return 0;
}
Ing. Ángel Sánchez Cruz Dr. Antonio Rodríguez Martínez Métodos numéricos, C++
Ing. Ángel Sánchez Cruz Dr. Antonio Rodríguez Martínez Métodos numéricos, C++