cofactors.php 822 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. *
  4. * Function code for the matrix cofactors() function
  5. *
  6. * @copyright Copyright (c) 2018 Mark Baker (https://github.com/MarkBaker/PHPMatrix)
  7. * @license https://opensource.org/licenses/MIT MIT
  8. */
  9. namespace Matrix;
  10. /**
  11. * Returns the cofactors of a matrix or an array.
  12. *
  13. * @param Matrix|array $matrix Matrix or an array to treat as a matrix.
  14. * @return Matrix The new matrix
  15. * @throws Exception If argument isn't a valid matrix or array.
  16. */
  17. if (!function_exists(__NAMESPACE__ . '\\cofactors')) {
  18. function cofactors($matrix): Matrix
  19. {
  20. if (is_array($matrix)) {
  21. $matrix = new Matrix($matrix);
  22. }
  23. if (!$matrix instanceof Matrix) {
  24. throw new Exception('Must be Matrix or array');
  25. }
  26. return Functions::cofactors($matrix);
  27. }
  28. }