Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.0 KiB

  1. package com.ugsbo.matrixcalc;
  2. /**
  3. * Contains all basic matrix math calculations.
  4. */
  5. public class MatrixCalcMath {
  6. /**
  7. * Mutliplys matrixA and matrixB.
  8. *
  9. * @param matrixA The Inputmatrix A (right TextArea in the GUI)
  10. * @param matrixB The Inputmatrix B (left TextArea in the GUI)
  11. * @return The Matrixproduct of the matricies A and B
  12. */
  13. public double[][] matrixMultiplication(double[][] matrixA, double[][] matrixB) {
  14. if (checkIfMatriciesAreLinked(matrixA, matrixB)) {
  15. int rowOfResultMatrix = matrixA.length;
  16. int columOfResultMatrix = matrixB[0].length;
  17. int ColumsOfMatA = matrixA[0].length;
  18. double[][] result = new double[rowOfResultMatrix][columOfResultMatrix];
  19. for (int rowResult = 0; rowResult < rowOfResultMatrix; rowResult++) {
  20. for (int columResult = 0; columResult < columOfResultMatrix; columResult++) {
  21. for (int columOfA = 0; columOfA < ColumsOfMatA; columOfA++) {
  22. result[rowResult][columResult] += matrixA[rowResult][columOfA] * matrixB[columOfA][columResult];
  23. }
  24. }
  25. }
  26. return result;
  27. } else {
  28. throw new IllegalArgumentException("array must be linked");
  29. }
  30. }
  31. /**
  32. * checks if matrixA and matrixB are linked to know if it is possible to
  33. * multiply them. If they are linked it is possible.
  34. *
  35. * @param matrixA The Inputmatrix A (right TextArea in the GUI)
  36. * @param matrixB The Inputmatrix B (left TextArea in the GUI)
  37. * @return true if you can Muliply A with B false if not.
  38. */
  39. public boolean checkIfMatriciesAreLinked(double[][] matrixA, double[][] matrixB) {
  40. if (matrixA != null) {
  41. if (matrixA[0].length == matrixB.length) {
  42. return true;
  43. } else {
  44. return false;
  45. }
  46. } else {
  47. return false;
  48. }
  49. }
  50. /**
  51. * Adds two matroices A and B. Adding matrix A to matrix B is the same as adding
  52. * B to A.
  53. *
  54. * @param matrixA The Inputmatrix A (right TextArea in the GUI)
  55. * @param matrixB The Inputmatrix B (left TextArea in the GUI)
  56. * @return The Matrixsum of matrix A and matrix B
  57. */
  58. public double[][] matrixAddition(double[][] matrixA, double[][] matrixB) {
  59. // TODO Sum each Element of matrix A to the corrosponding elem in B
  60. return null;
  61. }
  62. /**
  63. * In order to adding two Matricies they must have the same Dimensions. This
  64. * Methode checks if this is the case.
  65. *
  66. * @param matrixA The Inputmatrix A (right TextArea in the GUI)
  67. * @param matrixB The Inputmatrix B (left TextArea in the GUI)
  68. * @return true if the Dimensions of Matrix A equals the Dimensions Matrix B
  69. */
  70. public boolean checkIfMatriciesAreTheSameDimension(double[][] matrixA, double[][] matrixB) {
  71. // TODO Dimension check.
  72. return false;
  73. }
  74. }