#example of swamping#taken from Timothy Sauer's Numerical Analysis page 98
#a swamping problem#using double precision arithmeticm=matrix([[10.0^-20,1.0],[1.0,2.0]])b=vector([1.0,4.0])x=m.solve_right(b)#answer should be close to (2,1)#"swamping" problem occurs due to very small numbers used for pivot in Gaussian Elimination#10^20 + 1 ~= 10^20 in Gaussian Eliminationprintx
(0.000000000000000, 1.00000000000000)
#now first swap rows, then calculatem=matrix([[1.0,2.0],[10.0^-20,1.0]])b=vector([4.0,1.0])x=m.solve_right(b)#answer should be close to (2,1)printxprint"ta dah"