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