Why does RREF give significantly different answers than \ for solutions of some systems in MATLAB?

3 次查看(过去 30 天)
The documentation for MATLAB does not specify that the RREF function is intended for educational use and not recommended for practical applications. Consider the following code:
A = [87 54 71 34 51;26 33 49 31 23;57 9 107 28 7;30 21 89 27 44;55 5 6 7 8];
b = [29;41;91;0;38];
B = [A b];
C = rref(B);
which yields:
C(:,end) =
0.659722222222222
-0.461818181818182
-0.034894398530762
2.632286995515695
-1.774086378737542
whereas, using \ the solution is
A\b =
0.659729931133364
-0.461822077848193
-0.034894614961433
2.632290333420119
-1.774087558408285

采纳的回答

MathWorks Support Team
The discrepancy occurs because RREF attempts to produce rational solutions, with fairly small integers for the numerators and denominators, to systems which have coefficients that are "close to rational" as determined by approximating them via the function RAT. This behavior allows "nice" systems to have "nice" solutions when verifying hand calculations, thereby supporting the academic nature of RREF.
After performing Gauss-Jordan Elimination on the system, if the original coefficients were approximately rational as described above, then RREF calls RAT to find a simple rational approximation to the system's solution.
The attached MATLAB file, "rrefNoRational.m" is a copy of "rref.m" without the code that performs the rational conversion. Using this algorithm, the code:
A = [87 54 71 34 51;26 33 49 31 23;57 9 107 28 7;30 21 89 27 44;55 5 6 7 8];
b = [29;41;91;0;38];
B = [A b];
C = rrefNoRat(B);
returns
C(:,end) =
0.659729931133364
-0.461822077848194
-0.034894614961433
2.632290333420119
-1.774087558408284

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

产品


版本

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by