test.php 486 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. use Matrix\Matrix;
  3. use Matrix\Decomposition\QR;
  4. include __DIR__ . '/../vendor/autoload.php';
  5. $grid = [
  6. [1, 2],
  7. [3, 4],
  8. ];
  9. $targetGrid = [
  10. [-1],
  11. [-2],
  12. ];
  13. $matrix = new Matrix($grid);
  14. $target = new Matrix($targetGrid);
  15. $decomposition = new QR($matrix);
  16. $X = $decomposition->solve($target);
  17. echo 'X', PHP_EOL;
  18. var_export($X->toArray());
  19. echo PHP_EOL;
  20. $resolve = $matrix->multiply($X);
  21. echo 'Resolve', PHP_EOL;
  22. var_export($resolve->toArray());
  23. echo PHP_EOL;