Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main(){
- int i,j,a,tamanho_sist,max_inte;
- double erro_max;
- FILE *file;
- char nome_arq[60];
- do{
- printf("*****---SEJA BEM VINDO---*****\n\n\n\n\n");
- printf("Digite o diretorio do arquivo(inclua o .txt):\n");
- scanf("%[^\n]s",&nome_arq);
- fflush(stdin);
- file = fopen(nome_arq,"r");
- if(file == NULL){
- printf("\nErro ao abrir o arquivo, tente novamente \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
- system("pause");
- }
- system("cls");
- }while(file == NULL);
- fscanf(file,"%i %i %lf",&tamanho_sist,&max_inte,&erro_max);
- double *pont = (double *) calloc(tamanho_sist *(tamanho_sist+ 1), sizeof(double));
- double matriz[tamanho_sist][tamanho_sist + 1];
- //********** Funções declaradas após pegado os dados do arquivo***********----------------------------------------------------------------
- double jacobi(int n,double matriz[][n + 1],int max_inte,double erro_max){
- int i,j,contador,cont_erro;
- double konst,x[n],y[n];
- contador = 0;
- for(i=0;i<n;i++){
- x[i] = 0;
- y[i] = x[i];
- }
- do{
- cont_erro = 0;
- printf("\n\ninteracao no %i\t",contador + 1);
- for(i=0;i<n;i++){
- printf(" \tx(%i) = %.2lf\t",i+1,x[i]);
- }
- for(i=0;i<n;i++){
- konst = 0.0;
- for(j=0;j<n;j++){
- if(i != j){
- konst = konst + y[j]*matriz[i][j];
- }
- }
- x[i] = (matriz[i][n] - konst)/matriz[i][i];
- }
- for(i=0;i<n;i++){
- if(fabs(x[i]-y[i]) < erro_max){
- cont_erro++;
- }
- y[i] = x[i];
- }
- contador++;
- if(contador == max_inte){
- printf("\n\n\n\t**Maxima interacao atingida!**\n");
- break;
- }
- }while(cont_erro != n);
- if(cont_erro == n){
- printf("\n\n\t**Minimo erro atingido!**\n");
- }
- printf("\n\n\n\tValores encontrados:\n");
- for(i=0;i<n;i++){
- printf("\tx[%i] = %.2lf",i+1,x[i]);
- }
- printf("\n\n\n\n\n\n\n");
- }
- //********** Fim das declarações de funções***********------------------------------------------------------------------------------------
- printf("COonsiderando: tamanho do sistem = %i max intera = %i erromax = %lf\n",tamanho_sist,max_inte,erro_max);
- printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
- for(i=0;i<tamanho_sist;i++){
- for(j=0;j<tamanho_sist + 1;j++){
- fscanf(file,"%lf",&matriz[i][j]);
- }
- }
- fclose(file);
- system("pause");
- while(1){
- do{
- system("cls");
- printf("\nPara a sua matriz: \n");
- for(i=0;i<tamanho_sist;i++){
- for(j=0;j<tamanho_sist+1;j++){
- printf("\t%.1lf",matriz[i][j]);
- }
- printf("\n");
- }
- printf("\nEscolha uma operacao:\n");
- printf("1 *- Calcular pelo Metodo de Gauss-Jordan com pivotacao parcial.\n2 *- Calcular pelo Metodo de Gauss-Jordan sem pivotacao.\n3 *- Metodo iterativo de Jordan com dominancia por linha.\n4 *- Metodo iterativo de Seidel com dominancia por linha.\n5 *- Sair.\n");
- scanf("%i",&a);
- fflush(stdin);
- }while(a>5 || a<1);
- switch(a){
- case 1:
- system("cls");
- printf("\nvai pivotar e gauss-jordar\n");
- //1- FUNÇÃO DE PIVOTAÇÃO PARCIAL 2- FUNÇÃO Q CALCULA GAUSS-JORDAN
- system("pause");
- break;
- case 2:
- system("cls");
- printf("\nvai gaauss-jordar\n");
- //1- FUNÇÃO Q CALCULA GAUSS JORDAN
- system("pause");
- break;
- case 3:
- system("cls");
- printf("\nvai jordar\n");
- jacobi(tamanho_sist,matriz,max_inte,erro_max);
- system("pause");
- //1- FUNÇÃO DE PIVOTAÇÃO PARCIAL 2- FUNÇÃO Q CALCULA INT.JORDAN
- break;
- case 4:
- system("cls");
- printf("\nvai seidar \n");
- system("pause");
- //1- FUNÇÃO DE PIVOTAÇÃO PARCIAL 2- FUNÇÃO Q CALCULA PELO METODO INTERATIVO DE SEIDEL
- break;
- case 5:
- system("cls");
- return 0;
- break;
- default:
- printf("\nDigite um numero valido...\n");
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement