000
22.10.2006, 16:18 Uhr
NuCoder
|
Hallo Leute, vorneweg möchte ich mich entschuldigen, wenn ich trotz mehrfacher Suche diese Frage unnötig ins Forum setze. Ich muss eine Matrix*Matrix-Multiplikation und Matrix*Vektor-Multiplikation durchführen aber schon bei Matrix*Matrix habe ich meine Probleme. Die Matrizen werden zufällig generiert aber das Produkt liefert ein falsches Ergebnis. Ich bin leider kein guter bzw. kein erfahrener Programmierer, deshlab wäre ich für eure Hilfe sehr sehr dankbar
| C++: |
#include <iostream> #include <stdlib.h> using namespace std;
int main(void) { int mat[10][10]; int mat2[10][10]; int erg[10][10]; int dim; int i=0,j=0, k=0; int RANGE_MIN = 0; int RANGE_MAX = 2;
std::cout<<"Bitte Anzahl der Reihen :"<<endl; std::cin>>dim; std::cout<<"Matrix 1:"<<endl; for (i=1;i<=dim;i++) { for (j=1;j<=dim;j++) { mat[i][j]=(( (double) rand() /(double) RAND_MAX) * RANGE_MAX + RANGE_MIN); std::cout<<"\t"<<mat[i][j]; } std::cout<<"\n"<<endl;
}
std::cout<<"Matrix 2:"<<endl; for (i=1;i<=dim;i++) { for (j=1;j<=dim;j++) { mat2[i][j]=(((double) rand() /(double) RAND_MAX) * RANGE_MAX + RANGE_MIN); std::cout<<"\t"<<mat2[i][j]; } std::cout<<"\n"<<endl;
}
std::cout<<"Produkt:"<<endl; for (i=0; i<dim; i++) { for (j=0; j<dim; j++) { erg[i][j] = 0; for ( k=0; k<dim; k++) erg[i][j]+= mat[i][k]*mat2[k][j]; std::cout<<"\t"<<erg[i][j]; } std::cout<<"\n"<<endl; }
return 0;
}
|
|