Berechnung der inversen matrix???



  • Hallo,

    muss fürs studium einen programmentwurf in c++ schreiben und brauche dafür den eingabebefehl zur berechnung einer inversen 3x3 matrix. für die hilfe bin ich sehr dankbar.

    LG



  • Und was hast du bereits programmiert oder was hast du schon für Ideen???

    😃 Mein 400. Beitrag und 1 Jahr lang angemeldet!!! 😃



  • Teilen wir das Ganze mal ein bisschen auf:

    1. was brauchen wir?

    2. was müssen wir tun?

    - Zu invertierende Matrix(A),
    - Einheitsmatrix (Hauptdiagonale besteht aus Einsen)(I)

    Wir müssen Nullen unter den Pivotelementen erzeugen bzw. Zeilen so
    ummultiplizieren, dass sie mit anderen zeilen verrechnet werden können



  • Adjunktensatz FTW! Gauss ist bei so einer Minimatrix fester Größe totaler Overkill.



  • oder ne QR zerlegung,die ist wenigstens stabil 😉



  • Ja berechne die adjunkte, das ist das einfachste hier ein paar code snippets aus der klasse twoDimArr:
    (c) ZeuSOsC

    double minor(int x, int y)
            {
             double summe;
            twoDimArr copy(*this);
            copy.DelRow(x);
            copy.DelCol(y);
            summe=copy.det(0,0);
    
            return summe;
    		}
    
            double cofaktor(int x, int y)
            {
             double summe;
             twoDimArr copy(*this);
            summe=product_series(-1,x+y)*copy.minor(x,y); 
    
            return summe;
    		}
    
            twoDimArr Adjungated(void)
            {
    
             twoDimArr copy(*this);
             system("pause");
             for(int x=0;x<copy.Rows;x++){
                 for(int y=0;y<copy.Cols;y++){
                 copy.pArr[x*Cols + y]=this->cofaktor(x,y);}};
             copy.Transpose();
    
            return copy;
            }
    
            twoDimArr Inverse(void)
            {
             twoDimArr copy(*this);
             twoDimArr c(*this);
             double determinante;
             cout<<endl<<"Calulating Inverse of a "<<copy.Rows<<"x"<<copy.Cols<<" Matrix";
             determinante=copy.det(0,0);
              cout<<endl<<"det="<<determinante;
              if(determinante!=0)
              {
               copy=c.Adjungated();
               copy= ((double) 1)/((double) determinante) * copy;   
              }        
    
            return copy;         
            }
    

    und zum schluss noch die determinante:

    double det(int x, int y)
            {
             //berechnet determinante nach Laplaceschen Entwicklungssatz
             double summe=1;
             twoDimArr copy(*this);
             if(copy.Rows!=copy.Cols){return 0;};
    
             if((copy.Cols==1)&&(copy.Rows==1))
             {summe=copy[0][0]; 
    
             return summe;};
    
            if(copy.Cols==2){
            summe=( ((copy[0][0])*(copy[1][1])) - ((copy[0][1])* (copy[1][0])) );
            return summe;};
    
            summe=0; 
            for(int i=0;i<copy.Cols;i++)
            {if(copy[x][i]!=0){summe=summe+product_series(-1,i+2)*(copy[x][i])* (copy.minor(x,i));}
             }
    
             return summe;   
            }
    

    falls du noch ein paar fragen hast frage ruhig.
    mfg



  • Vielen Dank erstmal für die Hilfe 🙂


Anmelden zum Antworten