Thread: solution to a linear system of equations

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    3

    solution to a linear system of equations

    http://www.scs.carleton.ca/~wli/2404...Assign1W09.doc

    In the first part the procedure that I followed is as follows. Is it in accordance with the requirements.

    Code:
    class Main
    {
    public:
    Main(void);
    ~Main(void);
    void main(){
    double a[100][100], b[100][100], d[100][100], c[100], e[100], maxele, temp;
    
    cout<<" Please enter the number of unknowns: ";
    for(int i=0; i<n; i++){
    for(int j=0; j<n; j++)
    cin>>a[i][j];
    }
    for(int i=0; i<n; i++){
    cin>>c[i];
    }
    for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
    if(a[i][j]<0){
    b[i][j]=-1*a[i][j];
    }
    else{
    b[i][j]=a[i][j];
    }
    } 
    }
    
    int k=0;
    for(int i=0; i<n; i++){
    k<--i;
    while(j<n){
    if(a[i][j]>a[i][k]){
    temp<--a[i][k];
    a[i][k]<--a[i][j];
    a[i][j]<--temp;
    maxele<--a[i][k];
    j++;
    k++;
    }
    } 
    } 
    
    
    for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
    d[i][j]<--a[i][j]/a[i][1];
    }
    }
    
    for(int i=0; i<n; i++){
    if(a[i][1]<a[++i][1]){
    for(int j=0; j<n; j++){
    a[i][j]<--a[++i][j];
    }
    }
    }
    
    for(int i=0; i<n; i++){
    if(a[i][i]<1 && a[i][i]>1E-9){
    cout<<"the system does not have a unique solution";
    break;
    }
    else{
    for(int j=0; j<n; j++){
    a[i][j]<--a[i][j]-d[i][j];
    } 
    }
    }
    break;
    }
    
    static const int i=50;
    static const int j=50;
    
    while(i>0) do{
    while(j>0) do{
    if(a[i][j]<1 && a[i][j]>1E-9){
    break;
    }
    else{
    e[i]=(b[i]-a[i][--j])/a[i][j]; 
    }
    }
    }
    
    /*for(int i=sizeof a; i>0; i--){
    for(int j=sizeof a; j>0; j--){
    if(a[i][j]<1 && a[i][j]>1E-9){
    break;
    }
    else{
    e[i]=(b[i]-a[i][--j])/a[i][j]; 
    }
    }
    }*/
    }
    
    private:
    
    };

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I didn't read the requirements, but I doubt that your requirements are to write ... whatever that is. If it's supposed to be C++, it needs a heck of a lot of work. Your main program is never inside of a class. There's no reason to have a class if you don't need one, and you don't seem to need one. Are you using "<--" for assignment? In C++, that's "=". I'm sure there's more.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Like, what the hell happened to the poor whitespace? Don't you have any pity on that poor whitespace?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    i believe you've done the partial pivoting wrong.

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    This chunk of code is mysterious
    Code:
    double a[100][100], b[100][100], d[100][100], c[100], e[100], maxele, temp;
    
    cout<<" Please enter the number of unknowns: ";
    for(int i=0; i<n; i++){
    for(int j=0; j<n; j++)
    cin>>a[i][j];
    }
    n is not defined. Did you want to ask the user for n, and then ask him/her to enter n squared values? It seems n should be fixed at 100.
    Also, please indent your code: the logic is simple enough to follow, but the branches would be clearer with indentation.
    Last edited by CodeMonkey; 01-15-2009 at 09:01 PM. Reason: italics
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem With My Box
    By HaVoX in forum Tech Board
    Replies: 9
    Last Post: 10-15-2005, 07:38 AM
  2. Replies: 4
    Last Post: 06-13-2005, 09:03 AM
  3. Replies: 3
    Last Post: 06-13-2005, 07:28 AM
  4. Why Can't C++ Be Used to Develop Operating System?
    By Antigloss in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2005, 06:16 AM
  5. Solving linear equations
    By PJYelton in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2002, 06:00 PM