// Übung 3 - Aufgabe B (Matrix, Matrix Normen) // g++ -Wno-deprecated u3B.cc #include main() { const int NROWS = 57, MCOLS = 382; // Max. Anzahl von Matrixzeilen/spalten double a[NROWS][MCOLS]; // Matrix A double norm_F, norm_1, norm_inf; // die 3 Normen int n_row, m_col; // Anzahl Zeilen bzw. Spalten in Matrix A int i,j; // Laufvariable int iz; // Zaehler double sum; // Zeilensumme bzw, Spaltensumme (Hilfsgroesse) double aij; // Betrag von a[i][j] (Hilfsgroesse) // Eingabe cout << endl; cout << " Anzahl der Zeilen : "; cin >> n_row; cout << " Spalten : "; cin >> m_col; cout << endl; // Berechnung der Matrixeintraege // Achtung: Speicherung beginnt bei a[0,0], // daher muss a[i-1][j-1] verwendet werden!! iz = -1; // Zaehler in Zeile 1 hat negatives Vorzeichen for ( i=1; i<=n_row; i++ ) // Fuer alle Zeilen { for ( j=1; j<=m_col; j++ ) // Fuer alle Spalten in Zeile i { a[i-1][j-1] = iz/(1.0-(i+j)); // Achtung: 1.0 } iz = -iz; // alternierendes Vorzeichen } // Kontrollausgabe fuer kleine Matrizen if ( n_row < 10 && m_col < 10 ) { for ( i=0; i -1.0) for ( i=0; i norm_inf ) { norm_inf = sum; // max in Inf-norm } } norm_F = sqrt(norm_F); // Berechnung der 1-Norm // Zeilen- und Spaltenzyklus sind jetzt vertauscht norm_1 = -1.0; // Initialisierung Maximumsbildung // (Norm kann nie negativ sein ==> -1.0) for ( j=0; j norm_1 ) { norm_1 = sum; // max in 1-norm } } // Ausgabe der Normen cout << "Frobenius-norm : " << norm_F << endl; cout << " 1-norm : " << norm_1 << endl; cout << " Infinity-norm : " << norm_inf << endl; cout << endl; }