Buch Cover Buch Cover Buch Cover Buch Cover

Web-Code: - Webcode Help

Gleichungssystem (Felder)

Für 3D-Grafiken, Computerspiele und zur Lösung linearer Gleichungssysteme spielt die Matrixmultiplikation eine wesentliche Rolle. Lineare Gleichungssysteme haben die folgende Form:

5a + 7b = -10

 3a - 4b  = -88

Die obige Gleichung wird mit Matrizen wie folgt geschrieben:

$$\left( \begin{array}{cr} 5 \;\;\;\;\;\;\;\;\; 7 \\ 3 \;\;\;\;\;\; -4 \\ \end{array} \right) \left( \begin{array}{c} a\\ b \end{array} \right) = \left( \begin{array}{r} -10 \\ -88 \end{array} \right)$$

Die Zahlen 5, 7, 3 und -4 werden in ein doppelt indiziertes Array geschrieben:

m[0][0] := 5; m[0][1] := 7; m[1][0] := 3; m[1][1] := -4;

Mit dieser Definition können die rechten Seiten (-10, -88) für verschiedene Zahlen a und b leicht nach folgendem Schema errechnet werden:

mult(m: real[][]; ab: real[]): real[]
{
  xy: real[]
  xy := new real[2]
  row: integer
  row := 0
  while(row <= 1)
  {
    col: integer
    col := 0
    while(col <= 1)
    {
      xy[row] := xy[row] + m[row][col] * ab[col]
      col     := col + 1
    }
    row := row + 1
  }
  return xy
}

Rufen Sie obige Methode mit (a, b) = (-16, 10) auf.

Die rechte Seite sollte (x, y) = (-10, -88) lauten. Machen Sie von Hand zwei bis drei andere Vorausberechnungen, die Sie dann mit Ihrem Programm verifizieren.

0 Kommentare

Bitte melde dich an um einen Kommentar abzugeben

2 Lösung(en)

public class MatrixMult {
  public static void main(String[] args) {
    double [] ab = new double[2];
    ab[0] = - 16;
    ab[1] = 10;;
  
    double[][] m = new double[2][2];
    m[0][0] = 5;
    m[0][1] = 7;
    m[1][0] = 3;
    m[1][1] = -4;
    
    double [] xy;
    xy  = matMult(m, ab);
    System.out.println("x = " + xy[0] + "   y=" + xy[1]);
  }

  /**
   * Multipliziere [m] x (ab): Matrix mal Vektor
   */
  private static double[] matMult(double[][] m, double[] ab) {
    double [] xy = new double[2];
    int row = 0;
    while(row <=1) {
      int col = 0;
      while(col <= 1) {
        xy[row] = xy[row] + m[row][col] * ab[col];
        col = col + 1; }
      row = row + 1; }
    return xy; 
  }
} // end of class MatrixMult
                
function matrixProduct(mx1, mx2) {
  let result = [];
   for (let i = 0; i < mx1.length; i++)
     result.push(mx1[i][0] * mx2[0] + mx1[i][1] * mx2[1]);
  return result;
}

// test
let matrix = [ [5, 7], [3, -4] ];
console.log(matrixProduct(matrix, [-16, 10]));

let alpha = 1 / 8 * Math.PI;
matrix = [
  [Math.cos(alpha), Math.sin(alpha)],
  [Math.sin(alpha), Math.cos(alpha)]
];
console.log(matrixProduct(matrix, [-16, 10]));
                

Lösung von: Lisa Salander (Heidi-Klum-Gymnasium Bottrop)

Verifikation/Checksumme:

Werden für m[0][0] = cos(?), m[0][1] = -sin(?), m[1][0] = sin(?) und m[1][1] = cos(?) eingesetzt, so beschreibt die Matrixmultiplikation gerade eine Drehung des Punktes (x, y) um den Winkel ?.

Aktionen

Bewertung

Durchschnittliche Bewertung:

Eigene Bewertung:
Bitte zuerst anmelden

Meta

Zeit: 2
Schwierigkeit: Mittel
Webcode: k43i-8vjt
Autor: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

Download PDF

Download ZIP

Zu Aufgabenblatt hinzufügen