필터 지우기
필터 지우기

Why linsolve cannot solve this very simple equation?

조회 수: 4 (최근 30일)
Mr M.
Mr M. 2021년 4월 19일
답변: Steven Lord 2021년 4월 19일
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?

채택된 답변

Stephan
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

추가 답변 (1개)

Steven Lord
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]
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

카테고리

Help CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by