Here is my code:
A = [+0.00, -2.34, -2.25, -2.16, -2.07, -1.98, -1.89, -1.80, -0.72, +0.09, +1.16;
+2.34, +0.00, -3.15, -3.06, -2.97, -2.88, -2.79, -2.70, -1.26, -0.18, +0.98;
+2.25, +3.15, +0.00, -3.96, -3.87, -3.78, -3.69, -3.60, -1.80, -0.45, +0.80;
+2.16, +3.06, +3.96, +0.00, -4.77, -4.68, -4.59, -4.50, -2.34, -0.72, +0.62;
+2.07, +2.97, +3.87, +4.77, +0.00, -5.58, -5.49, -5.40, -2.88, -0.99, +0.44;
+1.98, +2.88, +3.78, +4.68, +5.58, +0.00, -6.39, -6.30, -3.42, -1.26, +0.26;
+1.89, +2.79, +3.69, +4.59, +5.49, +6.39, +0.00, -7.20, -3.96, -1.53, +0.08;
+1.80, +2.70, +3.60, +4.50, +5.40, +6.30, +7.20, +0.00, -2.00, -1.40, +0.00;
+0.72, +1.26, +1.80, +2.34, +2.88, +3.42, +3.96, +2.00, +0.00, -0.60, -0.24;
-0.09, +0.18, +0.45, +0.72, +0.99, +1.26, +1.53, +1.40, +0.60, +0.00, -0.42;
-1.16, -0.98, -0.80, -0.62, -0.44, -0.26, -0.08, +0.00, +0.24, +0.42, +0.00]
b = [1;1;1;1;1;1;1;1;1;1;1]
x = linsolve(a,b)
disp("Verification: (should be close to b)")
disp(A*x)
I am trying to find a solution x to Ax = b. However, the solution is very inaccurate, as verified by A*x not being close to equaling B.
The code gives this warning:
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.757657e-19.
As I understand it, my matrix has a very high “cond number”, which means it is close to being non-invertible and so the solution is changed a lot by roundoff errors, at least I believe.
So how do I work around this and get an accurate solution x?