Escolar Documentos
Profissional Documentos
Cultura Documentos
CANUA – Atividade 3
Resp.: Solução aproximada: {2, 2}; Erel=0,1395 Resp.: Solução aproximada: {2, -2, 2};
Erel=0,0457
#include <stdio.h>
#include <math.h>
void jacobi_3(double *res, double x1n, double x2n, double x3n, double epsi) {
double epsin = epsi + 1;
int i = 0;
printf("\nMétodo de Jacobi\n");
printf("=================\n\n");
if (x1 == 0) x1 = 1e-20;
if (x2 == 0) x2 = 1e-20;
if (x3 == 0) x3 = 1e-20;
epsin = fmax(fabs((x1n - x1) / x1), fmax(fabs((x2n - x2) / x2), fabs((x3n - x3) / x3)));
if (i > 50) {
printf("Não houve convergência após 50 iterações.\n");
res[0] = res[1] = res[2] = NAN;
return;
}
}
res[0] = x1n;
res[1] = x2n;
res[2] = x3n;
}
int main() {
double result[3];
double epsi = 1e-6;
Viviane Noecir dos Santos-SP3099415
double x1n = 0.0, x2n = 0.0, x3n = 0.0;
return 0;
}
#include <stdio.h>
#include <math.h>
void gauss_seidel_3(double *res, double x1n, double x2n, double x3n, double epsi) {
double epsin = epsi + 1;
int i = 0;
printf("\nMétodo de Gauss-Seidel\n");
printf("======================\n\n");
if (x1 == 0) x1 = 1e-20;
if (x2 == 0) x2 = 1e-20;
if (x3 == 0) x3 = 1e-20;
epsin = fmax(fabs((x1n - x1) / x1), fmax(fabs((x2n - x2) / x2), fabs((x3n - x3) / x3)));
if (i > 50) {
printf("Não houve convergência após 50 iterações.\n");
res[0] = res[1] = res[2] = NAN;
return;
}
}
res[0] = x1n;
res[1] = x2n;
Viviane Noecir dos Santos-SP3099415
res[2] = x3n;
}
int main() {
double result[3];
double epsi = 1e-6;
double x1n = 0.0, x2n = 0.0, x3n = 0.0;
return 0;
}