本文整理匯總了PHP中Matrix::hypo方法的典型用法代碼示例。如果您正苦於以下問題:PHP Matrix::hypo方法的具體用法?PHP Matrix::hypo怎麽用?PHP Matrix::hypo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Matrix
的用法示例。
在下文中一共展示了Matrix::hypo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: tql2
/**
* Symmetric tri-diagonal QL algorithm.
*
* This is derived from the Algol procedures tql2, by
* Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
* Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
* Fortran subroutine in EISPACK.
*
* @access private
*/
private function tql2()
{
for ($i = 1; $i < $this->n; ++$i) {
$this->e[$i - 1] = $this->e[$i];
}
$this->e[$this->n - 1] = 0.0;
$f = 0.0;
$tst1 = 0.0;
$eps = pow(2.0, -52.0);
for ($l = 0; $l < $this->n; ++$l) {
// Find small sub-diagonal element
$tst1 = max($tst1, abs($this->d[$l]) + abs($this->e[$l]));
$m = $l;
while ($m < $this->n) {
if (abs($this->e[$m]) <= $eps * $tst1) {
break;
}
++$m;
}
// If m == l, $this->d[l] is an eigenvalue,
// otherwise, iterate.
if ($m > $l) {
$iterator = 0;
do {
// Could check iteration count here.
$iterator += 1;
// Compute implicit shift
$g = $this->d[$l];
$p = ($this->d[$l + 1] - $g) / (2.0 * $this->e[$l]);
$r = Matrix::hypo($p, 1.0);
if ($p < 0) {
$r *= -1;
}
$this->d[$l] = $this->e[$l] / ($p + $r);
$this->d[$l + 1] = $this->e[$l] * ($p + $r);
$dl1 = $this->d[$l + 1];
$h = $g - $this->d[$l];
for ($i = $l + 2; $i < $this->n; ++$i) {
$this->d[$i] -= $h;
}
$f += $h;
// Implicit QL transformation.
$p = $this->d[$m];
$c = 1.0;
$c2 = $c3 = $c;
$el1 = $this->e[$l + 1];
$s = $s2 = 0.0;
for ($i = $m - 1; $i >= $l; --$i) {
$c3 = $c2;
$c2 = $c;
$s2 = $s;
$g = $c * $this->e[$i];
$h = $c * $p;
$r = Matrix::hypo($p, $this->e[$i]);
$this->e[$i + 1] = $s * $r;
$s = $this->e[$i] / $r;
$c = $p / $r;
$p = $c * $this->d[$i] - $s * $g;
$this->d[$i + 1] = $h + $s * ($c * $g + $s * $this->d[$i]);
// Accumulate transformation.
for ($k = 0; $k < $this->n; ++$k) {
$h = $this->V[$k][$i + 1];
$this->V[$k][$i + 1] = $s * $this->V[$k][$i] + $c * $h;
$this->V[$k][$i] = $c * $this->V[$k][$i] - $s * $h;
}
}
$p = -$s * $s2 * $c3 * $el1 * $this->e[$l] / $dl1;
$this->e[$l] = $s * $p;
$this->d[$l] = $c * $p;
// Check for convergence.
} while (abs($this->e[$l]) > $eps * $tst1);
}
$this->d[$l] = $this->d[$l] + $f;
$this->e[$l] = 0.0;
}
// Sort eigenvalues and corresponding vectors.
for ($i = 0; $i < $this->n - 1; ++$i) {
$k = $i;
$p = $this->d[$i];
for ($j = $i + 1; $j < $this->n; ++$j) {
if ($this->d[$j] < $p) {
$k = $j;
$p = $this->d[$j];
}
}
if ($k != $i) {
$this->d[$k] = $this->d[$i];
$this->d[$i] = $p;
for ($j = 0; $j < $this->n; ++$j) {
$p = $this->V[$j][$i];
//.........這裏部分代碼省略.........
示例2: __construct
//.........這裏部分代碼省略.........
for ($j = $i; $j < $this->m; $j++) {
$this->U[$j][$i] = 0.0;
}
}
++$this->U[$i][$i];
}
// Diagonalization of the bi-diagonal form
// Loop over singular values, and over allowed iterations.
$nm = 0;
for ($k = $this->n - 1; $k >= 0; $k--) {
for ($its = 0; $its < 30; $its++) {
$flag = true;
for ($l = $k; $l >= 0; $l--) {
$nm = $l - 1;
if ($l == 0 || abs($rv1[$l]) <= $eps * $aNorm) {
$flag = false;
break;
}
if (abs($this->W[$nm]) <= $eps * $aNorm) {
break;
}
}
if ($flag) {
$c = 0.0;
// Cancellation of rv1[l], if l > 0.
$s = 1.0;
for ($i = $l; $i < $k + 1; $i++) {
$f = $s * $rv1[$i];
$rv1[$i] = $c * $rv1[$i];
if (abs($f) <= $eps * $aNorm) {
break;
}
$g = $this->W[$i];
$h = Matrix::hypo($f, $g);
$this->W[$i] = $h;
$h = 1.0 / $h;
$c = $g * $h;
$s = -$f * $h;
for ($j = 0; $j < $this->m; $j++) {
$y = $this->U[$j][$nm];
$z = $this->U[$j][$i];
$this->U[$j][$nm] = $y * $c + $z * $s;
$this->U[$j][$i] = $z * $c - $y * $s;
}
}
}
$z = $this->W[$k];
if ($l == $k) {
if ($z < 0.0) {
$this->W[$k] = -$z;
// Singular value is made nonnegative.
for ($j = 0; $j < $this->n; $j++) {
$this->V[$j][$k] = -$this->V[$j][$k];
}
}
break;
}
if ($its == 29) {
print "no convergence in 30 svd iterations";
}
$x = $this->W[$l];
// Shift from bottom 2-by-2 minor.
$nm = $k - 1;
$y = $this->W[$nm];
$g = $rv1[$nm];
$h = $rv1[$k];