So what can we say about the solution? David and Walter have both told you the matrix really is singular. A singular matrix will offer no (unique) solution, even if a solution does exist.
A = [0.2500000000 0.00000000959994 0 -1 0 ; 0 0.2500000000000 0.0000000095999400 0 -1 ; 0.2500000000 0.00000000000075 0 -1 0 ; 0 0.2500000000000 0.0000000000007500 0 -1 ; 0.2500000000 0.00000000087634 0 -1 0]
A =
0.25 9.59994e-09 0 -1 0
0 0.25 9.59994e-09 0 -1
0.25 7.5e-13 0 -1 0
0 0.25 7.5e-13 0 -1
0.25 8.7634e-10 0 -1 0
B = [-1.30038272588598 ; 14.8832035274747 ;-2.15072625510578 ; 18.9956035209202 ;-1.75244493678615]
B =
-1.30038272588598
14.8832035274747
-2.15072625510578
18.9956035209202
-1.75244493678615
So, first, is A singular? Yes, I am afraid it is so. Frequently this means you have some fundamental problem in what the problem itsef means. It usually indicates there is insufficient information provided, or that there are numerical issues with how the problem was formulated. I cannot get into that, since only you know the source of this system.
As has been said, A is singular. How singular is it? We can lean a lot by looking at the singular values of A.
svd(A)
ans =
1.78535710713571
1.45773797371133
7.2817214828277e-09
6.7876523428981e-09
6.26786446143732e-19
And this clearly tells us that A is singular, at least numerically so. Comparing the number of singular values that are no larger than eps times the largest singular value is a way to determine the rank. Essentially since there is one tiny singular value in that set, then we know your matrix has one row or column that is a linear combination of the rest. The rank of A will be 4. However, even given that, A is still a matrix with some numerical issues, since I see there are two singular values as small as 1e-9.
Even given that however, a solution may still exist. We can learn if an exact solution exists by looking at the rank of the new matrix [A,B].
svd([A,B])
ans =
24.3688338660988
1.7807585310089
0.178093625927577
7.26504934395921e-09
5.42536835540766e-10
Essentially, this tells us that NO exact solution exists, because there is no way to write the vector B as a linear combination of the columns of the matrix A. Thus the matrix [A,B] now has rank 5, instead of rank 4.
Are we done then? Well, we can still try to flog this dead horse yet a few more times. How closely can we approximate the vector B?
You had a problem in working with pin, because there are tow small singular values of A that are not truly zero. They are actually relatively rather large, so they cause numerical problems.
pinv(A)
ans =
0.10209 -1.7044e-10 0.064906 -7.426e-11 0.068298
1.0841e+08 -5.217e-09 -6.1976e+07 5.217e-09 -4.6435e+07
-0.20149 1.0418e+08 0.11519 -1.0418e+08 0.086301
0.070798 -4.2609e-11 -0.53355 -1.8565e-11 -0.47842
2.7103e+07 7.8136e-05 -1.5494e+07 -1.0001 -1.1609e+07
You should see that pinv(A) has some relatively large numbers in it, as well as some quite small numbers. And this is why pinv(A)*B gives you crap. So let me see how well we can approximate B, using only TWO pieces of information, instead of trying to use all 4 of the technically linearly independent pieces of information in A.
Now, if we recall that A had two relatively large singular values, we might try to approximate A by a low rank (rank 2) approximation using the singular value decomposition.
pinvapprox = U(:,k)*diag(1./diag(S(k,k)))*V(:,k)';
So we might try this:
[B,A*xhat2]
ans =
-1.3004 -4.091
14.883 6.7053
-2.1507 -4.091
18.996 6.7053
-1.7524 -4.091
●
The first column is B, the second column is the best rank 2 approximation to B given the matrix A. They are very different, and that is a bad thing. It tells me that there will be no solution to your problem that does not involve quite large numbers. Another way of seeing this is to look at the projections of B onto the vectors in the columns of V.
V'*B
ans =
18.744
-5.3098
14.014
-2.1507
-3.3456
●
That the first two elements of that vector are relatively large is good. But we wanted the other three elements to be small. And they were not. In fact, B has a significantly large projectino onto the nullspace vector. We see that in the last element of thos product.
So I am sorry, but there exists NO solution for the problem A*x==b with small numbers in it that comes even remotely close to solving this linear system.
4 Comments
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/697040-since-the-matrix-is-near-to-singular-i-have-tried-pinv-to-solve-but-getting-too-deviated-answers-ca#comment_1215035
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/697040-since-the-matrix-is-near-to-singular-i-have-tried-pinv-to-solve-but-getting-too-deviated-answers-ca#comment_1215035
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/697040-since-the-matrix-is-near-to-singular-i-have-tried-pinv-to-solve-but-getting-too-deviated-answers-ca#comment_1215045
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/697040-since-the-matrix-is-near-to-singular-i-have-tried-pinv-to-solve-but-getting-too-deviated-answers-ca#comment_1215045
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/697040-since-the-matrix-is-near-to-singular-i-have-tried-pinv-to-solve-but-getting-too-deviated-answers-ca#comment_1215095
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/697040-since-the-matrix-is-near-to-singular-i-have-tried-pinv-to-solve-but-getting-too-deviated-answers-ca#comment_1215095
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/697040-since-the-matrix-is-near-to-singular-i-have-tried-pinv-to-solve-but-getting-too-deviated-answers-ca#comment_1215100
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/697040-since-the-matrix-is-near-to-singular-i-have-tried-pinv-to-solve-but-getting-too-deviated-answers-ca#comment_1215100
Sign in to comment.