Đăng Nhập

Vui lòng khai báo chính xác tên truy cập và mật khẩu!

Quên mật khẩu?

    Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy

      Trung Binh
      nienluan1

      Giới tính : Nam

      Tuổi : 34

      Đến từ : can tho

      Ngày Tham gia : 22/08/2012

      Tổng số bài gửi : 12

      #1

       Wed Aug 29, 2012 7:01 pm

      Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy


      Được sửa bởi nienluan1 ngày Wed Sep 05, 2012 8:59 pm; sửa lần 2.
      Tony Stark

      Giới tính : Nam

      Tuổi : 31

      Đến từ : Cần thơ

      Ngày Tham gia : 10/01/2012

      Tổng số bài gửi : 750

      #2

       Thu Aug 30, 2012 6:54 am

      bạn post lỗi lên luôn y dễ tìm hơn ^^!
      Trung Binh
      nienluan1

      Giới tính : Nam

      Tuổi : 34

      Đến từ : can tho

      Ngày Tham gia : 22/08/2012

      Tổng số bài gửi : 12

      #3

       Thu Aug 30, 2012 1:28 pm

      Bạn có code GIẢI HỆ PHƯƠNG TRÌNH TUYẾN TÍNH VỚI HỆ SỐ LÀ PHÂN SỐ BẰNG QUI TẮC CRAMER cho mình xin với tới ngày nộp rùi mà chưa làm xong nữa. Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy 3535839429
      Admin
      Admin

      Giới tính : Nam

      Đến từ : TPHCM

      Ngày Tham gia : 03/04/2011

      Tổng số bài gửi : 2292

      #4

       Thu Aug 30, 2012 7:46 pm

      nienluan1 đã viết:Bạn có code GIẢI HỆ PHƯƠNG TRÌNH TUYẾN TÍNH VỚI HỆ SỐ LÀ PHÂN SỐ BẰNG QUI TẮC CRAMER cho mình xin với tới ngày nộp rùi mà chưa làm xong nữa. Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy 3535839429
      của bạn đây






      Cài đặt Giải hệ phương trình tuyến tính bằng phương pháp khử Gauss trên ngôn ngữ lập trình C

      Code:
      #include "math.h"
      #include "conio.h"
      #include "iostream.h"

      /*Nhap ma tran he so*/
      double**NhapMaTran(int n){
        double**Temp;
        *Temp = new double[n];
        for(int i = 0; i<n; i++){
            Temp[i] = new double[n+1];
            for(int j = 0; j<=n; j++){
              if(j!=n)
                  cout<<"a["<<i<<"]["<<j<<"] = ";
              else
                  cout<<"b["<<i<<"] = ";
              cin>>Temp[i][j];
            }
        }
        return Temp;
      }

      /*Xuat ma tran*/
      void XuatMaTran(double**A, int n) {
        for(int i=0 ; i<n; i++){
            cout<<endl;
            for(int j=0 ; j<=n; j++)
              cout<<A[i][j]<<"\t";
        }
      }

      /*Xuat he phuong trinh tuyen tinh */
      void XuatHPT(double**A, int n) {
        for(int i=0 ; i<n; i++){
            cout<<endl<<A[i][0]<<".x0";
            for(int j=1 ; j<n; j++) {
              if(A[i][j]<0)
                  cout<<"\t"<<A[i][j]<<".x"<<j;
              else
                  cout<<"\t+"<<A[i][j]<<".x"<<j;
            }
            cout<<"\t = "<<A[i][n];
        }
      }

      void Exit(){
        asm {
            mov ah,4ch
            int 21h
        }
      }

      /*Chuong Trinh Chinh*/
      void main(){
        clrscr();
        int n;
        cout<<"Nhap Cap Cua Ma Tran n = ";
        cin>>n;
        double**A = NhapMaTran(n);
        //XuatMaTran(A,n);
        XuatHPT(A,n);
        A = NULL;
        getch();
        Exit();
      }

      crame

      Code:
      #include <stdio.h>
      #define nmax 20

      class vector
      {
          double v[nmax];
          int size;
          public:
              vector(int _size = nmax)
                  {
                      size = _size;
                      for (int k = 0; k < nmax; k++) v[k] = 0;
                  }

              double &operator [] (int k) { return v[k];}
              void show();
              void input();
      };

      void vector::input()
      {
          printf("\nSo phan tu cua vec to: ");
          scanf("%d",&size);
          for (int k = 0; k < size; k++)
              {
                  printf("[%d] = ", k);
                  scanf("%lf", &v[k]);
              }
      }

      void vector::show()
      {
          for (int k = 0; k < size; k++) printf("%8.2lf",v[k]);
          printf("\n");
      }

      class matrix
      {
          vector v[nmax];
          int rows, cols;
          public:
              matrix(int r = nmax, int c = nmax)
                  {
                      rows = r; cols = c;
                      for (int k = 0; k < nmax; k++) v[k] = vector();
                  }
              vector &operator [] (int k) { return v[k];}
              int issquare();
              matrix M(int, int);
              double mdeterm();
              matrix colreplace(int, vector);
              friend int cramer(matrix, vector, vector &);
              void input();
              void show();
      };

      int matrix::issquare() { return rows==cols;}

      void matrix::input()
      {
          printf("\nSo hang cua ma tran: ");
          scanf("%d",&rows);
          printf("\nSo cot cua ma tran: ");
          scanf("%d",&cols);

          for (int k = 0; k < rows; k++)
              for (int j = 0; j < cols; j++)
              {
                  printf("[%d][%d] = ", k,j);
                  scanf("%lf", &v[k][j]);
              }
      }

      void matrix::show()
      {
          for (int k = 0; k < rows; k++)
              {
                  for (int j = 0; j < cols; j++) printf("%8.2lf",v[k][j]);
                  printf("\n");
              }
      }

      matrix matrix::M(int m, int n)
      {
          matrix b = *this;
          int k, j;
          for (k = m; k < rows-1; k++)
              for (j = 0; j < cols; j++) b[k][j] = b[k+1][j];
          for (j = n; j < cols-1; j++)
              for (k = 0; k < rows; k++) b[k][j] = b[k][j+1];
          b.rows = rows-1; b.cols = cols-1;
          return b;
      }

      double matrix::mdeterm()
      {
          if (rows == 1) return v[0][0];
          double temp = 0;
          for (int k = rows-1; k >=0; k--)
              if ((cols + k) % 2)
                  temp -= v[k][cols-1]*M(k,cols-1).mdeterm();
              else
                  temp += v[k][cols-1]*M(k,cols-1).mdeterm();
          return temp;
      }

      matrix matrix::colreplace(int k, vector c)
      {
          matrix b = *this;
          for (int j = 0; j < rows; j++) b[j][k] = c[j];
          return b;
      }

      int cramer(matrix a, vector b, vector &x)
      {
          double det = a.mdeterm();
          if (det)
              {
                  x = vector(a.rows);
                  for (int k = 0; k < a.rows; k++)
                      x[k] = a.colreplace(k,b).mdeterm()/det;
                  return 1;
              }
          return 0;
      }

      void main()
      {
          matrix a(4,4);
          vector b, x;
          a.input();
          b.input();
          if (a.issquare())
              {
                  int status = cramer(a, b, x);
                  if (status)
                      {
                          printf("\nNghiem: ");
                          x.show();
                      }
                  else printf("\nHe suy bien\n");
              }
          else printf("\nHe khong tuong thich\n");


      Được sửa bởi Admin ngày Thu Aug 30, 2012 7:59 pm; sửa lần 1.
      Admin
      Admin

      Giới tính : Nam

      Đến từ : TPHCM

      Ngày Tham gia : 03/04/2011

      Tổng số bài gửi : 2292

      #5

       Thu Aug 30, 2012 7:49 pm

      ý tưởng
      Có hệ pt sau :
      ax + by = cz
      dx + ey = fz

      D = ae - bd
      Dx = ce - bf
      Dy = af - cd

      Ta giải được 2 nghiệm trên :
      x = Dx/D
      y = Dy/D

      Trường hợp mà basilisk kể trên chỉ là trường hợp riêng của hệ Crame thôi.

      Hệ Crame là hệ có ma trận liên kết A là ma trận vuông và det(A)!=0, tức là hệ PT tuyến tính n phương trình, n ẩn số. Muốn giải hệ này tổng quát thì đưa về ma trận, có 2 cách:

      1) Làm theo đúng CT: giả sử hệ có nghiệm X=[xj] thì xj=det(Aj)/det(A)

      2) Đưa ma trận đầy đủ A_ =[A|B] (B là cột hệ số) về dạng ma trận tam giác trên và giải từ dưới lên.

      cách giải 1
      Cách thứ nhất : Sử dụng ma trận nghịch đảo
      Code:
      oid MatAlgebra(double **x,double **a)
      {
          int i,j,k;
          double Sum,m;
          double **b, **q;
          b=new double *[N+1];
          q=new double *[N+1];
          for (i=1; i<=N; i++)
          {
              b[i] = new double [N+1];
              q[i] = new double [N+1];
          }
          for (i = 1; i <= N;i++)
              for (j = 1; j <= N;j++)
              {
                  b[i][j] = 0;
                  q[i][j] = a[i][j];
                  if (i == j)
                      b[i][j] = 1;
              }
          // Perform row operations
          for (k = 1;k <= N-1;k++)
              for (i = k+1;i <= N;i++)
              {
                  m = q[i][k]/q[k][k];
                  for (j = 1;j <= N;j++)
                  {
                      q[i][j] -= m*q[k][j];
                      b[i][j] -= m*b[k][j];
                  }
              }
      Cách thứ hai : Sử dụng định thức trong tam giác
      Code:
      double Determinant(double **a,int n)
      {
        int i,j,j1,j2;
        double det = 0;
        double **m = NULL;

        if (n < 1) { /* Error */

        } else if (n == 1) { /* Shouldn't get used */
            det = a[0][0];
        } else if (n == 2) {
            det = a[0][0] * a[1][1] - a[1][0] * a[0][1];
        } else {
            det = 0;
            for (j1=0;j1<n;j1++) {
              m = malloc((n-1)*sizeof(double *));
              for (i=0;i<n-1;i++)
                  m[i] = malloc((n-1)*sizeof(double));
              for (i=1;i<n;i++) {
                  j2 = 0;
                  for (j=0;j<n;j++) {
                    if (j == j1)
                        continue;
                    m[i-1][j2] = a[i][j];
                    j2++;
                  }
              }
              det += pow(-1.0,1.0+j1+1.0) * a[0][j1] * Determinant(m,n-1);
              for (i=0;i<n-1;i++)
                  free(m[i]);
              free(m);
            }
        }
        return(det);
      Trung Binh
      nienluan1

      Giới tính : Nam

      Tuổi : 34

      Đến từ : can tho

      Ngày Tham gia : 22/08/2012

      Tổng số bài gửi : 12

      #6

       Fri Aug 31, 2012 3:58 am

      Admin giúp mình làm hoàn chỉnh bài này nha mình học yếu môn này lắm Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy 3535839429
      Admin
      Admin

      Giới tính : Nam

      Đến từ : TPHCM

      Ngày Tham gia : 03/04/2011

      Tổng số bài gửi : 2292

      #7

       Fri Aug 31, 2012 9:34 am

      nienluan1 đã viết:Admin giúp mình làm hoàn chỉnh bài này nha mình học yếu môn này lắm Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy 3535839429

      đây bạn hoàn chỉnh rùi mà.mình bận lắm ko có nhiêu thời gian cho mấy việc này.
      bạn test xem
      Code:
      #include <stdio.h>
      #define nmax 20

      class vector
      {
          double v[nmax];
          int size;
          public:
              vector(int _size = nmax)
                  {
                      size = _size;
                      for (int k = 0; k < nmax; k++) v[k] = 0;
                  }

              double &operator [] (int k) { return v[k];}
              void show();
              void input();
      };

      void vector::input()
      {
          printf("\nSo phan tu cua vec to: ");
          scanf("%d",&size);
          for (int k = 0; k < size; k++)
              {
                  printf("[%d] = ", k);
                  scanf("%lf", &v[k]);
              }
      }

      void vector::show()
      {
          for (int k = 0; k < size; k++) printf("%8.2lf",v[k]);
          printf("\n");
      }

      class matrix
      {
          vector v[nmax];
          int rows, cols;
          public:
              matrix(int r = nmax, int c = nmax)
                  {
                      rows = r; cols = c;
                      for (int k = 0; k < nmax; k++) v[k] = vector();
                  }
              vector &operator [] (int k) { return v[k];}
              int issquare();
              matrix M(int, int);
              double mdeterm();
              matrix colreplace(int, vector);
              friend int cramer(matrix, vector, vector &);
              void input();
              void show();
      };

      int matrix::issquare() { return rows==cols;}

      void matrix::input()
      {
          printf("\nSo hang cua ma tran: ");
          scanf("%d",&rows);
          printf("\nSo cot cua ma tran: ");
          scanf("%d",&cols);

          for (int k = 0; k < rows; k++)
              for (int j = 0; j < cols; j++)
              {
                  printf("[%d][%d] = ", k,j);
                  scanf("%lf", &v[k][j]);
              }
      }

      void matrix::show()
      {
          for (int k = 0; k < rows; k++)
              {
                  for (int j = 0; j < cols; j++) printf("%8.2lf",v[k][j]);
                  printf("\n");
              }
      }

      matrix matrix::M(int m, int n)
      {
          matrix b = *this;
          int k, j;
          for (k = m; k < rows-1; k++)
              for (j = 0; j < cols; j++) b[k][j] = b[k+1][j];
          for (j = n; j < cols-1; j++)
              for (k = 0; k < rows; k++) b[k][j] = b[k][j+1];
          b.rows = rows-1; b.cols = cols-1;
          return b;
      }

      double matrix::mdeterm()
      {
          if (rows == 1) return v[0][0];
          double temp = 0;
          for (int k = rows-1; k >=0; k--)
              if ((cols + k) % 2)
                  temp -= v[k][cols-1]*M(k,cols-1).mdeterm();
              else
                  temp += v[k][cols-1]*M(k,cols-1).mdeterm();
          return temp;
      }

      matrix matrix::colreplace(int k, vector c)
      {
          matrix b = *this;
          for (int j = 0; j < rows; j++) b[j][k] = c[j];
          return b;
      }

      int cramer(matrix a, vector b, vector &x)
      {
          double det = a.mdeterm();
          if (det)
              {
                  x = vector(a.rows);
                  for (int k = 0; k < a.rows; k++)
                      x[k] = a.colreplace(k,b).mdeterm()/det;
                  return 1;
              }
          return 0;
      }

      void main()
      {
          matrix a(4,4);
          vector b, x;
          a.input();
          b.input();
          if (a.issquare())
              {
                  int status = cramer(a, b, x);
                  if (status)
                      {
                          printf("\nNghiem: ");
                          x.show();
                      }
                  else printf("\nHe suy bien\n");
              }
          else printf("\nHe khong tuong thich\n");
      }
      Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy Cramer10
      Trung Binh
      nienluan1

      Giới tính : Nam

      Tuổi : 34

      Đến từ : can tho

      Ngày Tham gia : 22/08/2012

      Tổng số bài gửi : 12

      #8

       Wed Sep 05, 2012 8:44 pm

      Admin ơi sau mình đưa code vào C++ Ctrl+F9 nhập số dòng và số cột là nó thoát ra hà
      tại sau vậy Admin (Giúp mình nha
      Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy 3535839429 )


      Trung Binh
      nienluan1

      Giới tính : Nam

      Tuổi : 34

      Đến từ : can tho

      Ngày Tham gia : 22/08/2012

      Tổng số bài gửi : 12

      #9

       Wed Sep 05, 2012 8:55 pm

      Admin đã viết:
      nienluan1 đã viết:Admin giúp mình làm hoàn chỉnh bài này nha mình học yếu môn này lắm Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy 3535839429
      Đoạn code này mình đưa vào c++ khi nhập số dòng số cột là nó thoat ra ha. Sau vậy Admin


      Code:
      #include <stdio.h>
      #define nmax 20

      class vector
      {
          double v[nmax];
          int size;
          public:
              vector(int _size = nmax)
                  {
                      size = _size;
                      for (int k = 0; k < nmax; k++) v[k] = 0;
                  }

              double &operator [] (int k) { return v[k];}
              void show();
              void input();
      };

      void vector::input()
      {
          printf("\nSo phan tu cua vec to: ");
          scanf("%d",&size);
          for (int k = 0; k < size; k++)
              {
                  printf("[%d] = ", k);
                  scanf("%lf", &v[k]);
              }
      }

      void vector::show()
      {
          for (int k = 0; k < size; k++) printf("%8.2lf",v[k]);
          printf("\n");
      }

      class matrix
      {
          vector v[nmax];
          int rows, cols;
          public:
              matrix(int r = nmax, int c = nmax)
                  {
                      rows = r; cols = c;
                      for (int k = 0; k < nmax; k++) v[k] = vector();
                  }
              vector &operator [] (int k) { return v[k];}
              int issquare();
              matrix M(int, int);
              double mdeterm();
              matrix colreplace(int, vector);
              friend int cramer(matrix, vector, vector &);
              void input();
              void show();
      };

      int matrix::issquare() { return rows==cols;}

      void matrix::input()
      {
          printf("\nSo hang cua ma tran: ");
          scanf("%d",&rows);
          printf("\nSo cot cua ma tran: ");
          scanf("%d",&cols);

          for (int k = 0; k < rows; k++)
              for (int j = 0; j < cols; j++)
              {
                  printf("[%d][%d] = ", k,j);
                  scanf("%lf", &v[k][j]);
              }
      }

      void matrix::show()
      {
          for (int k = 0; k < rows; k++)
              {
                  for (int j = 0; j < cols; j++) printf("%8.2lf",v[k][j]);
                  printf("\n");
              }
      }

      matrix matrix::M(int m, int n)
      {
          matrix b = *this;
          int k, j;
          for (k = m; k < rows-1; k++)
              for (j = 0; j < cols; j++) b[k][j] = b[k+1][j];
          for (j = n; j < cols-1; j++)
              for (k = 0; k < rows; k++) b[k][j] = b[k][j+1];
          b.rows = rows-1; b.cols = cols-1;
          return b;
      }

      double matrix::mdeterm()
      {
          if (rows == 1) return v[0][0];
          double temp = 0;
          for (int k = rows-1; k >=0; k--)
              if ((cols + k) % 2)
                  temp -= v[k][cols-1]*M(k,cols-1).mdeterm();
              else
                  temp += v[k][cols-1]*M(k,cols-1).mdeterm();
          return temp;
      }

      matrix matrix::colreplace(int k, vector c)
      {
          matrix b = *this;
          for (int j = 0; j < rows; j++) b[j][k] = c[j];
          return b;
      }

      int cramer(matrix a, vector b, vector &x)
      {
          double det = a.mdeterm();
          if (det)
              {
                  x = vector(a.rows);
                  for (int k = 0; k < a.rows; k++)
                      x[k] = a.colreplace(k,b).mdeterm()/det;
                  return 1;
              }
          return 0;
      }

      void main()
      {
          matrix a(4,4);
          vector b, x;
          a.input();
          b.input();
          if (a.issquare())
              {
                  int status = cramer(a, b, x);
                  if (status)
                      {
                          printf("\nNghiem: ");
                          x.show();
                      }
                  else printf("\nHe suy bien\n");
              }
          else printf("\nHe khong tuong thich\n");
      }
      Các bạn ơi xem code cua minh sai chỗ nào vậy mình tìm hoài không thấy Cramer10
      Tony Stark

      Giới tính : Nam

      Tuổi : 31

      Đến từ : Cần thơ

      Ngày Tham gia : 10/01/2012

      Tổng số bài gửi : 750

      #10

       Thu Sep 06, 2012 4:59 pm

      bạn nhập sai
      Trung Binh
      nienluan1

      Giới tính : Nam

      Tuổi : 34

      Đến từ : can tho

      Ngày Tham gia : 22/08/2012

      Tổng số bài gửi : 12

      #11

       Sun Sep 09, 2012 9:33 pm

      Tony Stack đã viết:bạn nhập sai

      Sai Chỗ Nào Vậy Bạn Chỉ Giúp Mình Với
      #12