/** * @expectedException \DomainException */ public function testAddException() { $arr1 = [[1, 2, 3, 4], [4, 5, 6, 7]]; $arr2 = [[1, 2, 3]]; $mat1 = new Matrix($arr1); $mat2 = new Matrix($arr2); $mat1->add($mat2); }
public function testAddException() { $m1 = new Matrix([[1, 2, 3], [4, 5, 6]]); $m2 = new Matrix([[7, 8], [9, 10], [11, 12]]); try { $m1->add($m2); } catch (MatrixException $exception) { return; } $this->fail('MatrixException not raised.'); }
/** * Fit first derivatives to minimise second derivatives. */ function fit_derivs_badly() { $n = $this->size() - 1; // there are 3*$n parameters to fit: polynomial coeffs of orders from 1 to 3 for each spline piece $M = new Matrix(3 * $n, 3 * $n); $b = array_fill(0, 3 * $n, 0); for ($i = 0; $i < $n; ++$i) { $dx = $this->points[$i + 1]->x - $this->points[$i]->x; $dx2 = $dx * $dx; $dx3 = $dx2 * $dx; $j = 3 * $i; $b[$j] = $this->points[$i + 1]->y - $this->points[$i]->y; $M->add($j, $j, $dx); // c_i^1 $M->add($j, $j + 1, $dx2); // c_i^2 $M->add($j, $j + 2, $dx3); // c_i^3 $M->add($j + 1, $j, 1); // c_i^1 $M->add($j + 1, $j + 1, 2 * $dx); // c_i^2 $M->add($j + 1, $j + 2, 3 * $dx2); // c_i^3 if ($i != $n - 1) { $M->add($j + 1, $j + 3, -1); } // c_{i+1}^1 $M->add($j + 2, $j + 1, 1); // c_i^2 $M->add($j + 2, $j + 2, 3 * $dx); // c_i^3 if ($i != $n - 1) { $M->add($j + 2, $j + 4, -1); } // c_{i+1}^2 } //$M->log(); //$M0 = $M->copy(); //echo 'b='.json_encode($b).'<br>'; $x = $M->solve($b); //echo 'b='.json_encode($M0->mulVect($x)).'<br>'; for ($i = 0; $i < $n; ++$i) { $j = 3 * $i; $p = $this->points[$i]; array_push($this->coeffs, array($p->y, $x[$j], $x[$j + 1], $x[$j + 2])); } $p = $this->points[$n]; array_push($this->coeffs, array($p->y, 0, 0, 0)); }
/** * @expectedException InvalidArgumentException */ public function testAddSizeFail() { $this->A->add($this->B); }