1. Weiterleitung zu NetzLiving.de
  2. Forum
    1. Unerledigte Themen
  3. zum neuen Forum
  • Anmelden
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Erweiterte Suche
  1. Informatik Forum
  2. Webmaster & Internet
  3. Entwicklung

Matrixmultiplikation

  • concrete_jungle
  • 18. November 2012 um 16:28
  • Unerledigt
Hallo zusammen,

das Informatik-Forum geht in den Archivmodus, genaue Informationen kann man der entsprechenden Ankündigung entnehmen. Als Dankeschön für die Treue bekommt man von uns einen Gutscheincode (informatikforum30) womit man bei netzliving.de 30% auf das erste Jahr sparen kann. (Genaue Infos sind ebenfalls in der Ankündigung)

Vielen Dank für die Treue und das Verständnis!
  • concrete_jungle
    Punkte
    10
    Beiträge
    1
    • 18. November 2012 um 16:28
    • #1

    Hallo,

    ich möchte ein Program schreiben, das eine 3x3 Matrix mit einem Vektor multipliziert, scheitere jedoch and der Funktion Matrixmultiplikation,

    Ich würde mich über eure Hilfe freuen!

    #include<stdio.h>
    #include<math.h>

    void Matrixmultipliktion(double b[], double Phi, double *x[])
    {
    int m, n=0;

    double Matrix [3][3]= {
    {cos(Phi), -sin(Phi), 0},
    {sin(Phi), cos(Phi), 0},
    {0,0,1} };

    for(m=0; m<3; m++)
    {
    x[m]=Matrix[m][n]*b[n];
    for(n=1; n<3; n++);
    {
    x[m]=x[m]+Matrix[m][n]*b[n];
    }
    }
    }


    int main()
    {
    double Phi=45./180*M_PI;
    double b[3]={1,2,3},x[3];

    Matrixmultiplikation(b[3], Phi, x[3]);

    printf(" %lf\n x= %lf\n %lf\n", x[0],x[1],x[2]);

    return 0;
    }

    Der Compiler sagt dazu:

    Matrix.c: 16:error: incompatible types in assignment
    Matrix.c:19: error: invalid operands to binary + (have ‘double *’ and ‘double’)
    Matrix.c: In function ‘main’:
    Matrix.c:30: warning: implicit declaration of function ‘Matrixmultiplikation’

    Zeile 16 ist: x[m]=Matrix[m][n]*b[n];
    Zeile 19 ist: x[m]=x[m]+Matrix[m][n]*b[n];

    Vielen Dank für eure Hilfe!

  • anwesender
    Punkte
    647
    Beiträge
    125
    • 19. November 2012 um 00:11
    • #2
    Zitat von concrete_jungle

    Hallo,

    ich möchte ein Program schreiben, das eine 3x3 Matrix mit einem Vektor multipliziert, scheitere jedoch and der Funktion Matrixmultiplikation,

    Ich würde mich über eure Hilfe freuen!

    Erstens: code-tag verwenden
    Zweitens: Für sowas gibt's GLM [1], boost [2], opencv [3] uvm., je nach zweck
    Drittens:
    * Was steht in x drin? du hast als typ (**double) somit bekommst du mit x[m] einen (*double)
    * Matrix[m][n]*b[n] -> Typ double; x[m] -> (*double)
    * ich vermute mal statt "x[m]=Matrix[m][n]*b[n];" sollte es "(*x)[m]=Matrix[m][n]*b[n]" sein
    * statt "Matrixmultiplikation(b[3], Phi, x[3])" sollte es eher "Matrixmultiplikation(b, Phi, &x)" sein
    * Schöner wäre es das x umzutypisieren auf double[] und dieses dann übergeben.

    Thomas

    [1]: http://glm.g-truc.net/
    [2]: http://www.boost.org/doc/libs/1_52_…s/doc/index.htm
    [3]: http://opencv.willowgarage.com/wiki/

  • spinball
    Punkte
    1.192
    Beiträge
    223
    • 19. November 2012 um 18:54
    • #3

    Ist die Rechenregel für Matrix x Vektor nicht

    Code
    | a b c |   | x |   | ax by cz |
    | d e f | * | y | = | dx ey fz |
    | g h i |   | z |   | gx hy iz |

    ?

    Entweder dein Ansatz ist vom Prinzip her falsch oder ich verstehe die Angabe nicht.

  • m4rS
    Punkte
    485
    Beiträge
    86
    • 19. November 2012 um 19:41
    • #4
    Zitat von spinball

    Ist die Rechenregel für Matrix x Vektor nicht

    Code
    | a b c |   | x |   | ax by cz |
    | d e f | * | y | = | dx ey fz |
    | g h i |   | z |   | gx hy iz |

    ?

    Entweder dein Ansatz ist vom Prinzip her falsch oder ich verstehe die Angabe nicht.


    Nope, für deinen Fall bräuchte man Matrix mit x,y,z in Diagonalen und zero otherwise statt dem Vektor

  • Maximilian Rupp 27. Dezember 2024 um 00:26

    Hat das Thema aus dem Forum Programmieren nach Entwicklung verschoben.

  1. Datenschutzerklärung
  2. Impressum