(*Examples of matrix conditioning*)

A = {{1, 3, -2, a}, {2, b, -1, 1}, {0, 4, 
          0, -2}, 
{1, 1, -2, 4}}

MatrixForm[A]

Det[A]

b = 0;

a = 0;

J = Inverse[A];

MatrixForm[J]

N[Eigenvalues[A . Transpose[A]]]

N[Eigenvalues[J . Transpose[J]]]

K = Sqrt[31.2] Sqrt[1.9]

bb  =  {1.1, -2.2, 2.9, 5.1}

bbnew  =  {1, -2, 3, 5}

JJ  =  N[J]

Det[JJ]

xx  =  J . bb

xxnew  =  JJ . bbnew

delB  =  bb  -  bbnew

relB  =  Sqrt[delB . delB]/Sqrt[bb . bb]

maxRelError  = K relB

delX =  xx - xxnew

relX  =  Sqrt[delX . delX]/Sqrt[xx . xx]

bb = {1015.7, 342.9, -44.8, -661.5}

bbnew = {1000, 340,  -45, -660}

xx = J . bb

xxnew = JJ . bbnew

delB  =  bb  -  bbnew

relB  =  Sqrt[delB . delB]/Sqrt[bb . bb]

K

maxRelError  =  K relB

delX =  xx  -  xxnew

relX  = Sqrt[delX . delX]/Sqrt[xx . xx]

(* Example 3;  same method,  
      this time with a large
    relative error in bb*) 

bb =  {0.123456,  2.41415,  -4.44444,  3.14159}

bbnew = {0, 2, -4, 3}

delB  =  bb - bbnew

relB  =  Sqrt[delB . delB]/Sqrt[bb . bb]

maxRelError  =  K relB

delX =  xx - xxnew

relX  =  Sqrt[delX . delX]/Sqrt[xx . xx]

MatrixForm[JJ]

r =.

s =.

bb = {r, 0, 0, 0}

bbnew = {s, 0, 0, 0}

delB = bb - bbnew

relB  =  Abs[r - s]/Abs[r]

maxRelErr =  K relB

xx =  J . bb

xxnew = JJ . bbnew

delX = xx - xxnew

relX =  Sqrt[delX . delX]/Sqrt[xx . xx]

r = -20

s = 10

maxRelError =  K relB

relX

N[xx]

xxnew

relB