/** * MINVERSE * * @param array $matrixValues A matrix of values * @return array */ public static function MINVERSE($matrixValues) { $matrixData = array(); if (!is_array($matrixValues)) { $matrixValues = array(array($matrixValues)); } $row = $maxColumn = 0; foreach ($matrixValues as $matrixRow) { $column = 0; foreach ($matrixRow as $matrixCell) { if (is_string($matrixCell) || $matrixCell === null) { return self::$_errorCodes['value']; } $matrixData[$column][$row] = $matrixCell; ++$column; } if ($column > $maxColumn) { $maxColumn = $column; } ++$row; } if ($row != $maxColumn) { return self::$_errorCodes['value']; } try { $matrix = new Matrix($matrixData); return $matrix->inverse()->getArray(); } catch (Exception $ex) { return self::$_errorCodes['value']; } }
public function testInverse() { $matrix = new Matrix([[1, 0, 5], [2, 1, 6], [3, 4, 0]]); $inverted = $matrix->inverse(); $result = new Matrix([[-24, 20, -5], [18, -15, 4], [5, -4, 1]]); $this->assertTrue($inverted->equals($result)); }
/** * MINVERSE * * @param array $matrixValues A matrix of values * @return array */ public static function MINVERSE($matrixValues) { $matrixData = array(); $row = 0; foreach ($matrixValues as $matrixRow) { $column = 0; foreach ($matrixRow as $matrixCell) { if (is_string($matrixCell) || $matrixCell === null) { return self::$_errorCodes['value']; } $matrixData[$column][$row] = $matrixCell; ++$column; } ++$row; } $matrix = new Matrix($matrixData); return $matrix->inverse()->getArray(); }
/** * @expectedException \RangeException */ public function testInverseException() { $arr1 = [[4, 3], [3, 2], [4, 5]]; $mat1 = new Matrix($arr1); $mat1->inverse(); }