Clear Filters
Clear Filters

Matrix is Singular to working precision

766 views (last 30 days)
Jacob Williams
Jacob Williams on 26 Apr 2017
Answered: theja on 30 Oct 2022
Hello, I am working on state space design, and have read through all the trouble shooting advice on this website for the above error. I have attached my code. The error is in line 43, the last one. I am not sure what I am doing that is causing this error. Could somebody guide me on what I am doing wrong? Please forgive the horrendous formating. I will also attach the file if that is easier to see.
% Defining parameters and state space model
R1 = 3.5e-3;
R2 = 0.45;
L1 = 1.8e-3;
L2 = 12e-3;
C = 50e-3;
A = [-R1/L1 -1/L1 0 0;
1/C 0 -1/C 0;
0 1/L2 -R2/L2 0;
0 1 0 0];
E = [-3-(R1/L1) -1/L1 0 0 0;
1/C -3.5 -1/C 0 0;
0 1/L2 -33-(R2/L2) 0 1/L1;
0 1 0 -0.5 0];
Ao = [-3 0 0 0 0;
0 -3.5 0 0 0;
0 0 -33 0 0;
0 0 0 -0.5 0;
0 0 0 0 -3
];
B = [1/L1; 0; 0; 0];
A_bar = [A E;zeros(5,4) Ao];
B_bar = [B;zeros(5,1)];
z = 0.9;
wn = 10;
p1 = roots([1 2*z*wn wn^2]);
poles = [-20 -40 p1'];
K = place(A,B,poles);
check = eig(A-B*K);
C = [0 1 0 0]; % C is Vc as given
Go =inv(C*inv(A - B*K)*B)*C*inv(A - B*K)*E
  1 Comment
Stephen23
Stephen23 on 1 May 2017
Edited: Stephen23 on 1 May 2017
The inv documentation explains that mldivide and mrdivide are faster and numerically more accurate compared to using inv and matrix multiplication.
The documentation clearly states "It is seldom necessary to form the explicit inverse of a matrix. A frequent misuse of inv arises when solving the system of linear equations Ax = b. One way to solve the equation is with x = inv(A)*b. A better way, from the standpoint of both execution time and numerical accuracy, is to use the matrix backslash operator x = A\b. This produces the solution using Gaussian elimination, without explicitly forming the inverse. See mldivide for further information."

Sign in to comment.

Answers (3)

Jayaram Theegala
Jayaram Theegala on 1 May 2017
The warning "Matrix is singular to working precision" occurs if the matrix for which you are trying to calculate the inverse is singular and hence the inverse does not exist.
From your MATLAB script, line 30, I can see that the value of "C*inv(A - B*K)*B" is zero, and hence if you try to calculate inverse for it, you will get that warning message.

Hafiz Qasim Ali
Hafiz Qasim Ali on 30 Apr 2021
Can anyone guide me how to resolve the issue? In case below code is not readable, please see the attachments.
function [f] = Objective_Function(x)
% First are defined the influent flow and depth of the pond.
Qi=209;
z=1.0;
% f = Total Cost and the retention time and number of screens are represented by x(1)and x(2), respectively;
f=5850*(x(1)*Qi/(3*z))+9600*sqrt(x(1)*Qi/(3*z))+2520*x(2)*sqrt(x(1)*Qi/(3*z));
function [c, ceq]= Constraints_Function(x)
Ni=58383.9;
T=11.8;
e=5;
z=1.0;
Qi=209;
DBOi=220;
kb=0.841*(1.075)^(T-20);
%c(1) represents the inequality constraint for the fecal coliform:c(1)= Ne-1000 <= 0
c(1)=(4*Ni*sqrt(1+4*kb*x(1)*3*0.7*(x(2)+1)^(2)/(-0.26118+0.25392*...
(3*0.7*(x(2)+1)^(2))+1.0136*(3*0.7*(x(2)+1)^(2))^(2)))...
*exp((1-sqrt(1+4*kb*x(1)*3*0.7*(x(2)+1)^(2)/(-0.26118+0.25392*...
(3*0.7*(x(2)+1)^(2))+1.0136*(3*0.7*(x(2)+1)^(2))^(2))))/(2*3*0.7*...
(x(2)+1)^(2)/(-0.26118+0.25392*(3*0.7*(x(2)+1)^(2))+1.0136*(3*0.7*...
(x(2)+1)^(2))^(2)))))/((1+sqrt(1+4*kb*x(1)*3*0.7*(x(2)+1)^(2)/...
(-0.26118+0.25392*(3*0.7*(x(2)+1)^(2))+1.0136*(3*0.7*(x(2)+1)^(2))...
^(2))))^(2))*(Qi/(Qi-0.001*3*x(1)*Qi/(3*z)*e))-1000;
%c(2) represents the inequality constraint for the BOD: %c(2)=BODe-75 <=0
c(2)=(DBOi/((1.2* x(1)/(1.085)^(35-T))+1))*(Qi/(Qi-0.001*3*x(1)*Qi/(3*z)*e))-75;
%ceq represent the equality constraints, but as there is none. Ceq is equal to cero.
ceq=0;
end
Warning: Matrix is singular to working precision.
> In backsolveSys
In solveKKTsystem
In computeTrialStep
In barrier
In fmincon (line 834)
In callSolver (line 32)
In optimguirun (line 40)
In optimguiswitchyard (line 14)

theja
theja on 30 Oct 2022
Matrix is singular to working precision.
X =
Inf
Inf

Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!