Why I am getting "Matrix is singular to working precision"?
33 views (last 30 days)
Show older comments
While solving the below equation, I am getting "Matrix is singular to working precision". What does it mean?
2w+3x+y-11z=1
5w-2x+5y-4z=5
w-x+3y-3z=3
3w+4x-7y+2z=-7
0 Comments
Answers (4)
Walter Roberson
on 28 Sep 2023
The equations have an infinite number of solutions. They are consistent but the 4th equation can be deduced from the previous 3.
When you have a matrix equation of the form A*x = b for matrix A and vector b and vectors of unknowns x, then the classic solution is to premultiply by inv(A) getting inv(A) * A * x = inv(A)*b and the inv(A) * A becomes the identity matrix by definition of matrix inverse, leading to x = inv(A) * b
But this fails if A is not an invertible matrix. When dealing with square matrices that are not invertible then we call those "singular"
So when you converted your system of equations to matrix form the coefficient matrix you got was singular, meaning that it is not invertible.
This is not a bug in MATLAB, this is a problem that your last equation does not give any new information so it is not possible to find a unique solution
0 Comments
Bruno Luong
on 28 Sep 2023
Edited: Bruno Luong
on 28 Sep 2023
The warning message is there "Matrix is singular to working precision" because your equations are dependent
% 2*w+3*x+y-11*z = 1 %(eqt1)
% 5*w-2*x+5*y-4*z = 5 %(eqt2)
% w-x+3*y-3*z = 3 %(eqt3)
% 3*w+4*x-7*y+2*z =-7 %(eqt4)
22*eqt1 + 45*eqt2 = 164*eqt3 + 35*eqt4.
In such case "\" cannot solve it (the result is garbage). You need to do something more intelligent.
You'll notice the coefficients of y is exactly the rhs, so ONE solution is
w=x=z=0, and y = 1
The general solution is (not telling you how I find it, but this is the fact)
z = randi([-10 10]) % arbitrary value, here I give integer in (-10,10)
w=0,
x=3*z,
y=1+2*z,
% Check
2*w+3*x+y-11*z
5*w-2*x+5*y-4*z
w-x+3*y-3*z
3*w+4*x-7*y+2*z
To check validity of using "\" you could enter the matrix of the linear system and check the rank
A=[ 2 3 1 -11;
5 -2 5 -4;
1 -1 3 -3;
3 4 -7 2]
rank(A)
The rank < 4 indicates you have singular system (having dependent equations)
0 Comments
Sam Chak
on 28 Sep 2023
Hi @Shakil
I attempted to replicate the results that displayed the warning message 'Matrix is singular to working precision.' From the message 'Matrix...' , I guess that you attempted to solve the system of linear equations in the matrix equation form to obtain by explicitly computing the matrix inverse. Therefore, we can conclude that you did not use the Gaussian elimination method.
The warning message implies that the system of linear equations is rank-deficient, resulting in an underdetermined system where there are more unknown variables than independent equations. This means that there are infinitely many solutions to the system. I have included a logical test for you to determine if the system has full rank.
Now that we have addressed the reason for receiving the warning message, would you like to continue pursuing the general solution as shown by@Bruno Luong?
syms w x y z c1
% system of linear equations
eqn1 = 2*w + 3*x + y -11*z == 1;
eqn2 = 5*w - 2*x + 5*y - 4*z == 5;
eqn3 = w - x + 3*y - 3*z == 3;
eqn4 = 3*w + 4*x - 7*y + 2*z ==-7;
eqns = [eqn1, eqn2, eqn3, eqn4];
v = [w, x, y, z];
% convert to matrix equation form, A*v = b
[A, b] = equationsToMatrix(eqns, v)
% Test 1
solv1 = inv(double(A))*double(b)
% Test 2
solv2 = double(A)\double(b)
% Determine if the system has full rank
% 1 means full rank (true), 0 means rank-deficient (false)
tf = logical(rank(A) == length(A))
1 Comment
Torsten
on 28 Sep 2023
Edited: Torsten
on 28 Sep 2023
syms w x y z c1 lambda
% system of linear equations
eqn1 = 2*w + 3*x + y -11*z == 1;
eqn2 = 5*w - 2*x + 5*y - 4*z == 5;
eqn3 = w - x + 3*y - 3*z == 3;
eqn4 = 3*w + 4*x - 7*y + 2*z ==-7;
eqns = [eqn1, eqn2, eqn3, eqn4];
v = [w, x, y, z];
% a special solution of the inhomogenous system
v_inhom = solve(eqns,v)
v_inhom = [v_inhom.w;v_inhom.x;v_inhom.y;v_inhom.z];
% convert to matrix equation form, A*v = b
[A, b] = equationsToMatrix(eqns, v)
% solution of homogeneous system
v_hom = null(A)
% general solution of linear system
v_sol = v_inhom + lambda*v_hom
% test general solution
subs(lhs(eqns)-rhs(eqns),[w x y z],[v_sol(1) v_sol(2) v_sol(3) v_sol(4)])
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!