NumericSquareMatrix.php 724 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace MathPHP\LinearAlgebra;
  3. use MathPHP\Exception;
  4. /**
  5. * Square matrix
  6. * Number of rows = number of columns
  7. * 1x1, 2x2, 3x3, etc.
  8. */
  9. class NumericSquareMatrix extends NumericMatrix
  10. {
  11. /**
  12. * Constructor
  13. *
  14. * @param array<array<int|float>> $A
  15. *
  16. * @throws Exception\MathException
  17. */
  18. public function __construct(array $A)
  19. {
  20. parent::__construct($A);
  21. if ($this->m !== $this->n) {
  22. throw new Exception\MatrixException('Not a square matrix; row count and column count differ');
  23. }
  24. }
  25. /**
  26. * Square matrix must be square
  27. *
  28. * @return bool
  29. */
  30. public function isSquare(): bool
  31. {
  32. return true;
  33. }
  34. }