0% found this document useful (0 votes)
31 views11 pages

Informe Lab 3 Metodos

This document is a laboratory report submitted by Efrain Castillo and Zorielis Ramírez to their professor Mariluz Centella. It summarizes the results of implementing three numerical methods - Gaussian elimination, Gauss-Jordan elimination, and Gauss-Seidel iteration - to solve systems of equations. Code examples are provided for each method.

Uploaded by

Efrain Castillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views11 pages

Informe Lab 3 Metodos

This document is a laboratory report submitted by Efrain Castillo and Zorielis Ramírez to their professor Mariluz Centella. It summarizes the results of implementing three numerical methods - Gaussian elimination, Gauss-Jordan elimination, and Gauss-Seidel iteration - to solve systems of equations. Code examples are provided for each method.

Uploaded by

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

República de Panamá

Sede Regional de Azuero

Universidad Tecnológica de Panamá

Métodos Numéricos

Informe de Laboratorio N.º 3

Profesora:
Mariluz Centella

Integrantes:

Efrain Castillo 6-721-1126


Zorielis Ramírez 6-721-1348

Fecha

7 de noviembre del 2017


Código
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

main(){

int z,b,n=1;

while(z<100){

printf("1 Eliminacion Gaussiana");


printf("\n2 Gauss Jordan");
printf("\n3 Gauss Seidel");

printf("\n\nSeleccionar metodo : ");


scanf("%d",&b);

switch (b){

case 1:

float A3a,A2a,A1a, mat4[10][10],


EC1Nx[10],EC2RMx[10],EC2Rx[10],EC3RMx[10],EC3Rx[10],EC2Nx[10],EA3Ma[10],EA3a[10];
int j,i;

printf("---ELIMINACION GAUSSIANA---\n\n");
printf("Ingrese datos a la matriz\n");
for(j=1;j<=3;j++){
printf("\nEcuacion %d\n",j);
for(i=1;i<=4;i++){

scanf("%f",&mat4[j][i]);

}//for i

}//for j
for(j=1;j<=3;j++){
printf("\n ");
for(i=1;i<=4;i++){
if(i==4){
printf("\t = %0.3f",mat4[j][i]);
}
else{
printf("\t %0.3f X%d",mat4[j][i],i);
}

for(j=1;j<=4;j++){

EC1Nx[j]=mat4[1][j]/mat4[1][1];

}
printf("\n\n Ecuacion normalizada #1");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC1Nx[j],j);
}

for(j=1;j<=4;j++){
EC2RMx[j]=EC1Nx[j]*+mat4[2][1];
EC2Rx[j]=mat4[2][j]-EC2RMx[j];
}
printf("\n\n Ecuacion reciente #2");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC2Rx[j],j);
}
for(j=1;j<=4;j++){
EC3RMx[j]=EC1Nx[j]*mat4[3][1];
EC3Rx[j]=mat4[3][j]-EC3RMx[j];
}
printf("\n\n Ecuacion reciente #3");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC3Rx[j],j);
}

for(j=2;j<=4;j++){

EC2Nx[j]=EC2Rx[j]/EC2Rx[2];

}
printf("\n\n Ecuacion normalizada #2");

for(j=2;j<=4;j++){
printf("\t %0.3f X%d",EC2Nx[j],j);
}

for(j=1;j<=4;j++){
EA3Ma[j]=EC2Nx[j]*EC3Rx[2];
EA3a[j]=EC3Rx[j]-EA3Ma[j];
}

printf("\n\n");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EA3a[j],j);
}

A3a=EA3a[4]/EA3a[3];
printf("\n\nEl valor de A3= %0.3f",A3a);
A2a=(EC2Rx[4]-EC2Rx[3]*A3a)/EC2Rx[2];
printf("\n\nEl valor de A2= %0.3f",A2a);

A1a=(mat4[1][4]-mat4[1][3]*A3a-mat4[1][2]*A2a)/mat4[1][1];
printf("\n\nEl valor de A1= %0.3f",A1a);

break;

case 2:

float mat[10][10],
EC1N[10],EC2RM[10],EC2R[10],EC3RM[10],EC3R[10],EC2N[10],EX3M[10],EX3[10],X3,X2,X1,EC1R2[
10],EC1R2M[10];
float EC3R2[10],EC3R2M[10];
float EC3N[10],EC1R3M3[10],EC1R3[10],EC2RM2[10],EC2R2[10];

printf("\n\n-----GAUSS JORDAN-----\n\n");
printf("\nRellenar matriz\n");
for(j=1;j<=3;j++){
printf("\nEcuacion %d\n",j);

for(i=1;i<=4;i++){
scanf("%f",&mat[j][i]);

}
}

for(j=1;j<=3;j++){
printf("\n ");
for(i=1;i<=4;i++){
if(i==4){
printf("\t = %0.3f",mat[j][i]);
}
else{
printf("\t %0.3f X%d",mat[j][i],i);
}
}

for(j=1;j<=4;j++){

EC1N[j]=mat[1][j]/mat[1][1];

}
printf("\n\n Ecuacion normalizada #1");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC1N[j],j);
}

for(j=1;j<=4;j++){
EC2RM[j]=EC1N[j]*+mat[2][1];
EC2R[j]=mat[2][j]-EC2RM[j];
}
printf("\n\n Ecuacion reciente #2");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC2R[j],j);
}

for(j=1;j<=4;j++){
EC3RM[j]=EC1N[j]*mat[3][1];
EC3R[j]=mat[3][j]-EC3RM[j];
}
printf("\n\n Ecuacion reciente #3");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC3R[j],j);
}

for(j=2;j<=4;j++){

EC2N[j]=EC2R[j]/EC2R[2];
}
printf("\n\n Ecuacion normalizada #2");

for(j=2;j<=4;j++){
printf("\t %0.3f X%d",EC2N[j],j);
}

for(j=1;j<=4;j++){
EC1R2M[j]=EC2N[j]*EC1N[2];
EC1R2[j]=EC1N[j]-EC1R2M[j];
}
printf("\n\n Primera ecuación reciente");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC1R2[j],j);
}

for(j=1;j<=4;j++){
EC3R2M[j]=EC2N[j]*EC3R[2];
EC3R2[j]=EC3R[j]-EC3R2M[j];
}

printf("\n\n Ecuacion reciente #3");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC3R2[j],j);
}

for(j=1;j<=4;j++){

EC3N[j]=EC3R2[j]/EC3R2[3];

}
printf("\n\n Ecuacion normalizada #3");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC3N[j],j);
}
for(j=1;j<=4;j++){
EC1R3M3[j]=EC3N[j]*EC1R2[3];
EC1R3[j]=EC1R2[j]-EC1R3M3[j];
}

printf("\n\n Ecuación reciente #1");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC1R3[j],j);
}

for(j=1;j<=4;j++){
EC2RM2[j]=EC3N[j]*EC2N[3];
EC2R2[j]=EC2N[j]-EC2RM2[j];
}

printf("\n\n Ecuacion reciente #2");

for(j=1;j<=4;j++){
printf("\t %0.3f X%d",EC2R2[j],j);
}

printf("\n");
for(j=1;j<=4;j++){
printf("\t %0.3f",EC1R3[j]);
}

printf("\n");
for(j=1;j<=4;j++){
printf("\t %0.3f",EC2R2[j]);
}

printf("\n");
for(j=1;j<=4;j++){
printf("\t %0.3f",EC3N[j],j);
}

break;
case 3:
int n=1;
float matr[3][4],x1,x2,x3,e1,e2,e3,xn1,xn2,xn3,eax1,eax2,eax3;

printf("Ingrese datos de las ecuaciones \n");

for(i=0;i<3;i++){
for(j=0;j<4;j++){
scanf("%f",&matr[i][j]);
}//for i
}//for j

printf("Introduzca los valores aproximados para X1, X2 y X3 respectivamente \n");


scanf("%f %f %f", &e1, &e2, &e3);

x1=(-1)*matr[0][1],(-1)*matr[0][2],matr[0][3],matr[0][0];
x2=(-1)*matr[1][2],matr[1][3],matr[1][1];
x3=(-1)*matr[2][1],matr[2][3],matr[2][2];

x1= matr[0][3]/matr[0][0];
x2=(-1*matr[1][0]*x1)+matr[1][3]/matr[1][1];
x3=((-1)*matr[2][0]*x1+(-1)*matr[2][1]*x2+ matr[2][3])/matr[2][2];

while(n==1){
xn1=((-1)*matr[0][1]*x2+(-1)*matr[0][2]*x3+matr[0][3])/matr[0][0];
xn2=((-1)*matr[1][0]*xn1+(-1)*matr[1][2]*x3+matr[1][3])/matr[1][1];
xn3=((-1)*matr[2][0]*xn1+(-1)*matr[2][1]*xn2+matr[2][3])/matr[2][2];

printf("\n x3=%0.3f\n", xn3);

eax1=fabs(((xn1-x1)/xn1*100));
printf("\n-Error en x1: %0.3f", eax1);

eax2=fabs((xn2-x2)/xn2*100);
printf("\n-Error en x2: %0.3f", eax2);
eax2=fabs((xn3-x3)/xn3*100);
printf("\n-Error en x3: %0.3f", eax3);

x1=xn1;
x2=xn2;
x3=xn3;

printf("\n%0.3f", x1);
printf("\n%0.3f", x2);
printf("\n%0.3f", x3);

if((eax1<e1)||(eax2<=e2)||(eax3<x3)){
n=2;
}
}

break;

}//switch

z=z+1;
}//while todo
getch();
}

Anexos
 Gauss Jordan

Eliminación Gaussiana

You might also like