(** SISTEMI LINEARI **)

(* PIVOTING *)

Clear[a];

a={{0.003,59.14},{5.291,-6.13}};
x={x1,x2};
b={59.17,46.78};
ab={Join[a[[1]],{b[[1]]}],Join[a[[2]],{b[[2]]}]};
MatrixForm[a]
MatrixForm[b]
MatrixForm[x]
MatrixForm[ab]
sys=Dot[a,x]==b
Solve[sys,x]

ab1={ab[[1]],ab[[2]]-ab[[1]]*(ab[[2]][[1]]/ab[[1]][[1]])};
MatrixForm[ab1]

x2sol=ab1[[2]][[3]]/ab1[[2]][[2]]
x1sol=(ab1[[1]][[3]]-ab1[[1]][[2]]*x2sol)/ab1[[1]][[1]]

Clear[a,ab,ab1,b]
eps=1.0*10^(-20);
a={{eps,2.1},{5.2,-3.1}};
b={a[[1]][[1]]+10*a[[1]][[2]],a[[2]][[1]]+10*a[[2]][[2]]};
ab={Join[a[[1]],{b[[1]]}],Join[a[[2]],{b[[2]]}]};
MatrixForm[a]
MatrixForm[b]
MatrixForm[ab]
sys=Dot[a,x]==b
Solve[sys,x]

ab1={ab[[1]],ab[[2]]-ab[[1]]*(ab[[2]][[1]]/ab[[1]][[1]])};
MatrixForm[ab1]
x2sol=ab1[[2]][[3]]/ab1[[2]][[2]]
x1sol=(ab1[[1]][[3]]-ab1[[1]][[2]]*x2sol)/ab1[[1]][[1]]

ab2={ab[[2]],ab[[1]]}
ab1={ab2[[1]],ab2[[2]]-ab2[[1]]*(ab2[[2]][[1]]/ab2[[1]][[1]])};
MatrixForm[ab1]
x2sol=ab1[[2]][[3]]/ab1[[2]][[2]]
x1sol=(ab1[[1]][[3]]-ab1[[1]][[2]]*x2sol)/ab1[[1]][[1]]