25 private $QR = array();
55 $this->QR = $A->getArrayCopy();
56 $this->m = $A->getRowDimension();
57 $this->
n = $A->getColumnDimension();
63 $nrm =
hypo($nrm, $this->QR[$i][$k]);
67 if ($this->QR[$k][$k] < 0) {
71 $this->QR[$i][$k] /= $nrm;
73 $this->QR[$k][$k] += 1.0;
75 for ($j = $k+1; $j <
$this->n; ++$j) {
78 $s += $this->QR[$i][$k] * $this->QR[$i][$j];
80 $s = -$s/$this->QR[$k][$k];
82 $this->QR[$i][$j] += $s * $this->QR[$i][$k];
86 $this->Rdiag[$k] = -$nrm;
101 if ($this->Rdiag[$j] == 0) {
118 $H[$i][$j] = $this->QR[$i][$j];
137 $R[$i][$j] = $this->QR[$i][$j];
139 $R[$i][$j] = $this->Rdiag[$i];
155 for ($k = $this->
n-1; $k >= 0; --$k) {
160 for ($j = $k; $j <
$this->n; ++$j) {
161 if ($this->QR[$k][$k] != 0) {
163 for ($i = $k; $i <
$this->m; ++$i) {
164 $s += $this->QR[$i][$k] * $Q[$i][$j];
166 $s = -$s/$this->QR[$k][$k];
167 for ($i = $k; $i <
$this->m; ++$i) {
168 $Q[$i][$j] += $s * $this->QR[$i][$k];
193 if ($B->getRowDimension() ==
$this->m) {
196 $nx = $B->getColumnDimension();
197 $X = $B->getArrayCopy();
200 for ($j = 0; $j < $nx; ++$j) {
202 for ($i = $k; $i <
$this->m; ++$i) {
203 $s += $this->QR[$i][$k] *
$X[$i][$j];
205 $s = -$s/$this->QR[$k][$k];
206 for ($i = $k; $i <
$this->m; ++$i) {
207 $X[$i][$j] += $s * $this->QR[$i][$k];
212 for ($k = $this->n-1; $k >= 0; --$k) {
213 for ($j = 0; $j < $nx; ++$j) {
214 $X[$k][$j] /= $this->Rdiag[$k];
216 for ($i = 0; $i < $k; ++$i) {
217 for ($j = 0; $j < $nx; ++$j) {
218 $X[$i][$j] -=
$X[$k][$j]* $this->QR[$i][$k];
223 return (
$X->getMatrix(0, $this->n-1, 0, $nx));