Skip to content

Instantly share code, notes, and snippets.

@anthonylgf
Last active May 30, 2018 12:55
Show Gist options
  • Save anthonylgf/e1705d23f0fbb075eb67a277b483bb26 to your computer and use it in GitHub Desktop.
Save anthonylgf/e1705d23f0fbb075eb67a277b483bb26 to your computer and use it in GitHub Desktop.
Questão B-3, 3 lista de exercícios de CN
#include<stdio.h>
#include<math.h>
void upper(double[][4], double[]);
void createMatriz(double[][4]);//cria a matriz
void printMatriz(double[][4]);
int main(void){
double listaCoeficientes[6] = {0,0,0,0,0,0};
double matriz[4][4];//matriz principal
createMatriz(matriz); //inicia a matriz com os valores
upper(matriz, listaCoeficientes);
}
void upper(double matriz[4][4], double lista[]){
int count;
for(int i=1, count=0; i<4; i++,count++){
lista[count] = (matriz[i][0]/matriz[0][0]);
for(int j=0; j<4; j++){
matriz[i][j] = matriz[i][j] - lista[count]*matriz[0][j];
}
}
for(int i=2, count=3; i<4; i++,count++){
lista[count] = matriz[i][1]/matriz[1][1];
for(int j=1; j<4; j++){
matriz[i][j] = matriz[i][j]-lista[count]*matriz[1][j];
}
}
for(int i=3, count=5; i<4; i++,count++){
lista[count] = matriz[i][2]/matriz[2][2];
for(int j=2; j<4; j++){
matriz[i][j] = matriz[i][j]-lista[count]*matriz[2][j];
}
}
printf("A matriz U:\n");
printMatriz(matriz);
double matrizL[4][4];
matrizL[0][0] = 1.0;
matrizL[1][0] = lista[0];
matrizL[2][0] = lista[1];
matrizL[3][0] = lista[2];
matrizL[1][1] = 1.0;
matrizL[2][1] = lista[3];
matrizL[3][1] = lista[4];
matrizL[3][2] = lista[5];
matrizL[0][1] = 0.0;
matrizL[0][2] = 0.0;
matrizL[0][3] = 0.0;
matrizL[1][2] = 0.0;
matrizL[1][3] = 0.0;
matrizL[2][2] = 1.0;
matrizL[2][3] = 0.0;
matrizL[3][3] = 1.0;
printf("A matriz L:\n");
printMatriz(matrizL);
}
void printMatriz(double matriz[4][4]){
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
printf("%lf ", matriz[i][j]);
}
printf("\n");
}
printf("\n");
}
void createMatriz(double matriz[4][4]){
matriz[0][0] = M_PI;
matriz[0][1] = -M_E;
matriz[0][2] = sqrt(2);
matriz[0][3] = -sqrt(3);
matriz[1][0] = M_PI * M_PI;
matriz[1][1] = M_E;
matriz[1][2] = -(M_E * M_E);
matriz[1][3] = 3.0/7.0;
matriz[2][0] = sqrt(5);
matriz[2][1] = -sqrt(6);
matriz[2][2] = 1.0;
matriz[2][3] = -sqrt(2);
matriz[3][0] = M_PI * M_PI * M_PI;
matriz[3][1] = M_E * M_E;
matriz[3][2] = -sqrt(7);
matriz[3][3] = 1.0/9.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment