/** * Solves a system of linear equations: Ax = b * * A system such as: * <pre> * a11*x1 + a12*x2 + ... + a1n*xn = b1 * a21*x1 + a22*x2 + ... + a2n*xn = b2 * ... * ak1*x1 + ak2*x2 + ... + akn*xn = bk * </pre> * can be rewritten as: * <pre> * Ax = b * </pre> * where: * - A is matrix of coefficients (aij, i=1..k, j=1..n), * - b a vector of values (bi, i=1..k), * - x the vector of unkowns (xi, i=1..n) * Using: x = (Ainv)*b * where: * - Ainv is the inverse of A * * @static * @access public * @param object Math_Matrix $a the matrix of coefficients * @param object Math_Vector $b the vector of values * @return mixed a Math_Vector object on succcess, PEAR_Error otherwise * @see vectorMultiply() */ function solve($a, $b) { // check that the vector classes are defined if (!Math_Matrix::isMatrix($a) && !Math_VectorOp::isVector($b)) { return PEAR::raiseError('Incorrect parameters, expecting a Math_Matrix and a Math_Vector'); } $e = $a->invert(); if (PEAR::isError($e)) { return $e; } return $a->vectorMultiply($b); }
function testIsMatrix() { $this->assertTrue(Math_Matrix::isMatrix($this->m)); }