Gaussian elimination: Difference between revisions
m
C++ - avoid division by zero
(Added C++ solution) |
m (C++ - avoid division by zero) |
||
Line 834:
=={{header|C++}}==
{{trans|Go}}
<lang cpp>#include <
#include <cassert>
#include <cmath>
#include <iomanip>
Line 904 ⟶ 905:
for (size_t i = k; i < n; ++i) {
// compute scale factor = max abs in row
scalar_type scale_factor =
for (size_t j = k; j < n; ++j)
// scale the abs used to pick the pivot
scalar_type abs = std::abs(a(i, k))/scale_factor;
|