Why linsolve cannot solve this very simple equation?
9 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Stephan
2021-4-19
编辑:Stephan
2021-4-19
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
0 个评论
更多回答(1 个)
Steven Lord
2021-4-19
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]
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]
sol3 = sol1 + 42*N; % A*(sol1+42*N) = A*sol1 + 42*A*N = B+0 = B
[sol3, A*sol3-B] % Also close to 0
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stochastic Differential Equation (SDE) Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!