Jump to content

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 <cassertalgorithm>
#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 = -10;
for (size_t j = k; j < n; ++j) {
scalar_type valuescale_factor = std::max(std::abs(a(i, j)), scale_factor);
if (valuescale_factor >== scale_factor0)
scale_factor = valuecontinue;
}
// scale the abs used to pick the pivot
scalar_type abs = std::abs(a(i, k))/scale_factor;
1,777

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.