Advertisement
luizaspan

Escalonamento (Eliminação Gaussiana)

Sep 9th, 2015
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define N 4
  5.  
  6. int main(void)
  7. {
  8.     double A[N][N]={{2,1,4,1},{3,4,-1,-1},{1,-4,1,5},{2,-2,1,3}}, b[N]={-4,3,9,7};
  9.     int i,j,k;
  10.  
  11.     for (i=0;i<N;i++)
  12.     {
  13.         for (j=i+1;j<N;j++)
  14.         {
  15.             double c=A[j][i]/A[i][i];
  16.  
  17.             for (k=i;k<N;k++)
  18.             {
  19.                 A[j][k]=A[j][k] - c*A[i][k];
  20.             }
  21.  
  22.             b[j]=b[j]-c*b[i];
  23.         }
  24.     }
  25.  
  26.     for (i=0;i<N;i++)
  27.     {
  28.         for (j=0;j<N;j++)
  29.         {
  30.             printf("%8.3lf",A[i][j]);
  31.  
  32.             if (j==(N-1))
  33.                 printf("\n");
  34.             else
  35.                 printf(" ");
  36.         }
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement