Why linsolve cannot solve this very simple equation?

9 Ansichten (letzte 30 Tage)
Mr M.
Mr M. am 19 Apr. 2021
Beantwortet: Steven Lord am 19 Apr. 2021
A = [4,2,2; 5,1,3; 6,0,4];
B = [60; 70; 80];
X = linsolve(A,B)
The solution should be 6, 7, 11, since:
4x6 + 2x7 + 2x11 = 60
5x6 + 1x7 + 3x11 = 70
6x6 + 0x7 + 4x11 = 80
But I get the following answer:
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =
7.401487e-18.
X = [0; 10; 20]
Why?

Akzeptierte Antwort

Stephan
Stephan am 19 Apr. 2021
Bearbeitet: Stephan am 19 Apr. 2021
To solve this, the rank should be 3. Row 1 and 3 are not linear independent.
A = [4,2,2; 5,1,3; 6,0,4]
B = [60; 70; 80];
r1 = rank(A)
r2 = rank([A, B])
linsolve gives a correct solution, because there are more then 1 solutions, due to the rank:
>> X = linsolve(A,B)
Test = A*X
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =
7.401487e-18.
X =
0
10
20
Test =
60
70
80

Weitere Antworten (1)

Steven Lord
Steven Lord am 19 Apr. 2021
The vector [6; 7; 11] is a solution to the problem but it is not the only solution.
A = [4,2,2; 5,1,3; 6,0,4];
B = [60; 70; 80];
sol1 = [6; 7; 11];
check = A*sol1-B; % should be close to 0
[sol1, check]
ans = 3×2
6 0 7 0 11 0
N = null(A); % A*N is close to the 0 vector
sol2 = sol1 + N; % Since A*sol1 = B and A*N = 0, A*(sol1+N) = B+0 = B
check2 = A*sol2-B; % should also be close to 0
[sol2, check2]
ans = 3×2
5.4655 0 7.2673 0 11.8018 0
sol3 = sol1 + 42*N; % A*(sol1+42*N) = A*sol1 + 42*A*N = B+0 = B
[sol3, A*sol3-B] % Also close to 0
ans = 3×2
-16.4499 -0.0000 18.2250 -0.0000 44.6749 0.0000

Kategorien

Mehr zu Stochastic Differential Equation (SDE) Models finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by