solver for AX=B by gauss elimination

i need a program to solve AX=B by gauss elimination.
sandeepyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
deluxeConnect With a Mentor Commented:
try this..my teacher made me do it..and here it is..just..make it dynamic array..

#include "stdafx.h"
#include "iostream.h"
#include "iomanip.h"
#include "math.h"

int main() {
  int lngth;
  cout << "Size of matrix:\n";
  cin >> lngth;
  if (lngth>10) return 0;
    double a[10][10], b[10], x,      y, z[10];
    for (int ix=0; ix<=lngth-1; ix++) {
      for (int iy=0; iy<=lngth-1; iy++) {
      cout << "Term of "<< ix+1 << "x" << iy+1 << ":";
      cin >> a[iy][ix];
      }
    cout << "Please enter solution for this equation" << ":";
    cin >> b[ix];
  }
  for (int u=0; u<=lngth-1; u++) {                        
    for (int v=0; v<=lngth-1; v++) {                    
      if (a[u][v]!=0) {                                                
      if (double(a[u][v])!=1) {                              
        cout << setw(3) <<a[u][v];                        
      } else {                                                      
        cout << setw(3) << " ";                              
      }                                                                  
      cout << char('a'+v);                                    
      if (v!=lngth-1) {
        cout << " +";                                          
      }                                                                  
      } else {                                                            
      cout << setw(6) << " ";                                    
      }
    }                                                                              
  cout << "\t = " << b[u];                                          
  cout << '\n';                                                            
  }                                                                                    

      
      for (int i=0; i<=lngth-1; i++) {                        
            for (int j=0; j<=lngth-1; j++){                                    
                  x=a[i][i];                                                            
                  y=a[j][i];                                                            
                  if (x==0) {
                        for (int h=0; h<=lngth-1; h++) {
                              if ((h!=i)&&(a[h][i]!=0)) {
                                          for (int w=0; w<=lngth-1; w++) {
                                                a[i][w]=a[i][w]+a[h][w];
                                          }
                                          b[i]=b[i]+b[h];
                                          break;
                              }
                        }
                  }
                  if ((x!=1)&&(x!=0)) {
                        for (int m=0; m<=lngth-1; m++) {      
                              a[i][m]=a[i][m]/x;                        
                        }                                                      
                        b[i]=b[i]/x;                                    
                  }
                  if  ((!(i==j))&&(y!=0)) {                        
                        for (int k=0; k<=lngth-1; k++) {      
                              a[j][k]=(a[i][k]*y)-(a[j][k]);      
                        }
                        float s=(b[i]*y), t=(b[j]);
                        if (s-t==0) {
                              b[j]=0;                                          
                        } else {
                              b[j]=(b[i]*y)-(b[j]);
                        }
                  }                                                                  
            }                                                                        
      }                                                                                    
      cout << '\n';                                                                              
      for (int l=0; l<=lngth-1; l++) {                                                
            z[l]=(double)(b[l])/(double)(a[l][l]);                                    
            cout << char('a'+l) << "=" <<setprecision(20) << z[l] <<"\n";
      }                                                                                                
return 0;      
}
0
 
sumant032199Commented:
Don't you think some more explanation is required?
0
 
flobiesCommented:
Do your own linear algebra homework. Hint: your professor will know that BLAS at netlib is too complex for you to write yourself. Please remember to strip off the comments so that it's not too obvious. He/she will still recognize it, of course.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
snifongCommented:
I am willing to help but I am not going to do it for you.  Post some code.
0
 
940961slCommented:
Can you solve AX=B with gauss elimination?? I thought gauss elimination was for equations like ax² +bx + c = 0.
the solution for AX=B is X=B/A isn't it??
Or is it so long ago that i'm wrong?

0
 
ozoCommented:
Well, yes, if you want to use Gauss-Jordan elimination to compute A¯¹
0
All Courses

From novice to tech pro — start learning today.