Easy example of $Ax =b$ floating point arithmetic.

77 Views Asked by At

Solve $Ax =b$ with two-digit floating-point arithmetic.

We have $$ A= \begin{pmatrix} 1 & 1\\ 1 & 0,99\\ \end{pmatrix} $$ and

$$ b = \begin{pmatrix} -1 \\ 1 \\ \end{pmatrix} $$

So I get : $$ \left[ \begin{array}{cc|c} 1&1&-1\\ 0&1\cdot10^{-2}&2 \end{array} \right] $$

for $x$ I got $$ x=\begin{pmatrix} 199 \\ -200 \\ \end{pmatrix} $$ but the solution says that $$ x=\begin{pmatrix} -200 \\ 200 \\ \end{pmatrix} $$ is correct, but why? Remark: it seems so that the solution has a mistake. it should be (200,-200)

I know that this question could be very easy for a lot of people. I am a complete amateur in terms of floating point arithmetic.

2

There are 2 best solutions below

1
On

The problem said that you were working in "two digit floating point arithmetic". "-199" rounded to two digits is "-200".

1
On

Looks like you tried doing it by inverting $A$. Since $A$ is nearly singular (the determinant is $0.01$, while the average entry is about $1$), there is a high risk of numerical instability (floating point errors becoming larger than approximation errors).

So, let's try solving your system by Gaussian elimination: $$ \left. \begin{array}{rrrrr} x_{1} & + & x_{2} & = & -1\\ x_{1} & + & 0.99 x_{2} & = & 1\\ \end{array} \right\} \Rightarrow \left\{ \begin{array}{rrrrr} x_{1} & + & x_{2} & = & -1\\ & & -0.01 x_{2} & = & 2\\ \end{array}\right\} $$ The last equation gives us $x_{2} = -200$, so $x_{1} = 199$. This calculation differs from yours only by a minus sign, and differs principally from the other answer you cite from your source.