Blame view

vendor/markbaker/matrix/examples/test.php 486 Bytes
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  <?php
  
  use Matrix\Matrix;
  use Matrix\Decomposition\QR;
  
  include __DIR__ . '/../vendor/autoload.php';
  
  $grid = [
      [0, 1],
      [-1, 0],
  ];
  
  $targetGrid = [
      [-1],
      [2],
  ];
  
  $matrix = new Matrix($grid);
  $target = new Matrix($targetGrid);
  
  $decomposition = new QR($matrix);
  
  $X = $decomposition->solve($target);
  
  echo 'X', PHP_EOL;
  var_export($X->toArray());
  echo PHP_EOL;
  
  $resolve = $matrix->multiply($X);
  
  echo 'Resolve', PHP_EOL;
  var_export($resolve->toArray());
  echo PHP_EOL;