wie kann ich das sklaraprodukt einer nxn Matrix mit einem n-Vektor ?



  • wie kann ich das sklaraprodukt einer nxn Matrix mit einem n-Vektor ?
    danke



  • Was kannst du damit?



  • ein Matrix nXn multiplizieren mit ein Vektor v .mein Problem dass ich nicht dass Prinzip verstehe wie sol ich das ambesten machen
    danke



  • Ist das ein mathematisches Problem? Was verstehst du genau nicht?
    So kann dir doch keiner helfen. 🙄



  • z.b:

    #include <vector>
    using namespace std;
    
    typedef vector<double> Vector;
    typedef vector<Vector> Matrix;
    
    void Mul(const Matrix & A, const Vector & v, Vector * res) {
      // Prufung
      if (res == NULL) throw "res ist NULL!";
      int c = v.size ();
      int r = A.size ();
      res->clear ();
    
      for (int i =0; i < r; i++)
      {
         if (A[i].size () != c) throw "Dimension Feheler!";
         double val = 0;
         for (int j = 0; j < c; j++) val += A[i][j] * v[j];
         res->push_back (val);
      }
    
    }
    

    und Matrix initialisierung:

    Matrix test;
     Vector r(4);
     for (int i =0;i i< 4;i++)
      test.push_back (r);
    // Jetzt test is 4x4 Matrix, alle elementen sind null
     test [a][b] = something; // Initialisierung von element in der Zeile a, Spalte b...
    

Anmelden zum Antworten