Skip to content

Commit 63c73f4

Browse files
committed
Name some variables.
1 parent 82e339c commit 63c73f4

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/LUDecomposition.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,30 +137,29 @@ private function rowPivot($thisRow, $thatRow)
137137
}
138138

139139
/**
140-
* Solves a linear set of equations in the form A * x = b for x, where A
141-
* is the decomposed matrix of coefficients (now P*L*U), $x is the vector
142-
* of unknowns, and $b is the vector of knowns.
140+
* Solves a linear set of equations in the form A * unknown = known for unknown, where A
141+
* is the decomposed matrix of coefficients (now P*L*U)
143142
*
144-
* @param array $b vector of knowns
145-
* @return array $x The solution vector
143+
* @param array $known
144+
* @return array
146145
* @throws MatrixException
147146
*/
148-
public function solve(array $b)
147+
public function solve(array $known)
149148
{
150149
$rowCount = $this->getRowCount();
151150

152-
if (count($b) !== $rowCount) {
153-
throw new MatrixException('The knowns vector must be the same size as the coefficient matrix.');
151+
if (count($known) !== $rowCount) {
152+
throw new MatrixException('The known vector must be the same size as the coefficient matrix.');
154153
}
155154

156-
$y = []; // L*y = b
157-
$x = []; // U*x = y
155+
$y = []; // L * y = b
156+
$unknown = []; // U * unknown = y
158157

159158
$skip = true;
160159

161160
// Solve L * y = b for y (forward substitution)
162161
for ($i = 0; $i < $rowCount; ++$i) {
163-
$this_b = $b[$this->permutations[$i]]; // Unscramble the permutations
162+
$this_b = $known[$this->permutations[$i]]; // Unscramble the permutations
164163
if ($skip && $this_b == 0) { // Leading zeroes in b give zeroes in y.
165164
$y[$i] = 0;
166165
} else {
@@ -177,18 +176,18 @@ public function solve(array $b)
177176
}
178177
}
179178

180-
// Solve U * x = y for x (backward substitution)
179+
// Solve U * unknown = y for unknown (backward substitution)
181180
for ($i = $rowCount - 1; $i >= 0; --$i) {
182-
$x[$i] = $y[$i];
181+
$unknown[$i] = $y[$i];
183182

184183
for ($j = $i + 1; $j < $rowCount; ++$j) {
185-
$x[$i] = $x[$i] - $this->get($i, $j) * $x[$j];
184+
$unknown[$i] = $unknown[$i] - $this->get($i, $j) * $unknown[$j];
186185
}
187186

188-
$x[$i] = $x[$i] / $this->get($i, $i); // Keep division out of the inner loop
187+
$unknown[$i] = $unknown[$i] / $this->get($i, $i); // Keep division out of the inner loop
189188
}
190189

191-
return $x;
190+
return $unknown;
192191
}
193192

194193
/**

0 commit comments

Comments
 (0)