Reduced row echelon form: Difference between revisions

Content added Content deleted
m (Used "<M" and "<N" in "toMatrix" instead of "a.high" and "a[0].high".)
m (Use "strformat".)
Line 2,708: Line 2,708:
===Using floats===
===Using floats===
When using floats, we have to be careful when doing comparisons. The previous program adapted to use floats instead of rationals may give wrong results. This would be the case with the second matrix. To get the right result, we have to do a comparison to an epsilon rather than zero. Here is the program modified to work with floats:
When using floats, we have to be careful when doing comparisons. The previous program adapted to use floats instead of rationals may give wrong results. This would be the case with the second matrix. To get the right result, we have to do a comparison to an epsilon rather than zero. Here is the program modified to work with floats:
<lang Nim>import strutils
<lang Nim>import strutils, strformat


const Eps = 1e-10
const Eps = 1e-10
Line 2,761: Line 2,761:
for val in row:
for val in row:
line.addSep(" ", 0)
line.addSep(" ", 0)
line.add val.formatFloat(ffDecimal, 2).align(7)
line.add &"{val:7.2f}"
echo line
echo line