public function evaluate(array $params)
 {
     $m = $this->m;
     $n = $this->n;
     $R = [];
     for ($i = 0; $i < $m; $i++) {
         for ($j = 0; $j < $n; $j++) {
             $func = $this->A[$i][$j];
             $R[$i][$j] = $func($params);
         }
     }
     return MatrixFactory::create($R);
 }
 /**
  * @dataProvider dataProviderForFrobeniusNorm
  */
 public function testFrobeniusNorm(array $A, $norm)
 {
     $A = MatrixFactory::create($A);
     $this->assertEquals($norm, $A->frobeniusNorm(), '', 0.0001);
 }
 /**
  * @dataProvider dataProviderForRowExclude
  */
 public function testRowExclude(array $A, int $mᵢ, array $R)
 {
     $A = MatrixFactory::create($A);
     $R = MatrixFactory::create($R);
     $this->assertEquals($R, $A->rowExclude($mᵢ));
 }
Beispiel #4
0
 /**
  * @dataProvider dataProviderForJsonSerialize
  */
 public function testJsonSerialize(array $A, string $json)
 {
     $A = MatrixFactory::create($A);
     $this->assertEquals($json, json_encode($A));
 }
 /**
  * @dataProvider dataProviderForSolve
  * Compute the RREF before trying to solve.
  */
 public function testSolveRREF(array $A, array $b, array $expected)
 {
     $A = MatrixFactory::create($A);
     $b = new Vector($b);
     $expected = new Vector($expected);
     $A->rref();
     $x = $A->solve($b);
     $this->assertEquals($expected, $x, '', 0.001);
 }
 /**
  * Axiom: det(A ⊗ B) = det(A)ᵐ det(B)ⁿ
  * Determinant of Kronecker product - where A is nxn matrix, and b is nxn matrix
  * @dataProvider dataProviderForKroneckerProductDeterminant
  */
 public function testKroneckerProductDeterminant(array $A, array $B)
 {
     $A = MatrixFactory::create($A);
     $B = MatrixFactory::create($B);
     $det⟮A⟯ᵐ = $A->det() ** $B->getM();
     $det⟮B⟯ⁿ = $B->det() ** $A->getN();
     $det⟮A⊗B⟯ = $A->kroneckerProduct($B)->det();
     $this->assertEquals($det⟮A⊗B⟯, $det⟮A⟯ᵐ * $det⟮B⟯ⁿ, '', 0.0001);
 }
 public function testCofactorMatrixExceptionNotSquare()
 {
     $A = MatrixFactory::create([[1, 2, 3, 4], [2, 3, 4, 4], [3, 4, 5, 4]]);
     $this->setExpectedException('MathPHP\\Exception\\MatrixException');
     $A->cofactorMatrix();
 }
 /**
  * @dataProvider dataProviderForEye
  */
 public function testEye(int $m, int $n, int $k, int $x, array $R)
 {
     $A = MatrixFactory::eye($m, $n, $k, $x);
     $R = MatrixFactory::create($R);
     $this->assertEquals($R, $A);
     $this->assertEquals($R->getMatrix(), $A->getMatrix());
     $this->assertEquals($m, $R->getM());
     $this->assertEquals($n, $R->getN());
 }
 /**
  * @dataProvider dataProviderForColumnExclude
  */
 public function testColumnExclude(array $A, int $nᵢ, array $R)
 {
     $A = MatrixFactory::create($A);
     $R = MatrixFactory::create($R);
     $this->assertEquals($R, $A->columnExclude($nᵢ));
 }