Why does Matlab have a different solution than mine? I tried other software, and they give me the same solution.

조회 수: 3 (최근 30일)
%matrix A, and vector of constants b
A = [2 1 0 0 0; 1 1 -1 0 -1; -1 0 1 0 1; 0 -1 0 1 1; 0 1 1 1 1]
b = [100; 0; 50; 120; 0]
%augmented matrix
Ab = [A b]
%row reduction
[rowreducedAb, pivotvarsAb] = rref(Ab)
%free and basic variables
[numqns, numvars] = size(A)
[numrows, numpivotvars] = size(pivotvarsAb)
numfreevars = numvars - numpivotvars
%LU decomposition of A
[L,U] = lu(A)
y = L\b
%inverse of U
invU = inv(U)
%original solution
x = invU*y
%cramer's rule
A1 = A
A1(:,1) = b
x1 = det(A1)/det(A)
My Solution:
Matrix A Vector of unknows Vector of constants
2 1 0 0 0 x1 100
1 1 -1 0 -1 x2 0
-1 0 1 0 1 x3 50
0 -1 0 1 1 x4 120
0 1 1 1 1 x5 0
Fourth Step: Gaussian Eliminations;
B + C -> B x2 = 50
A - B -> A x1 = 25
D + E -> D
D - C -> D
D) x1 + x5 = 70 x5 = 45
C) -x1 + x3 + x5 = 50 x3 = 25 - 45 + 50 x3 = 30
E) x2 + x3 - x4 + x5 = 0 50 + 30 + 45 = x4 x4 = 125

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 16일
Back substitute on your proposed solution
>> A*[25;50;30;125;45]
ans =
100
0
50
120
250
The first four entries match b, but the last entry of b is 0 not 250. Your solution is incorrect.
>> A\b
ans =
25
50
-220
-125
295
>> A*[25;50;-220;-125;295]
ans =
100
0
50
120
0
MATLAB's solution works.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by