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;
|
|