Created
October 27, 2014 05:05
-
-
Save oldaccountarchived/bab430b00701c3db48ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diary on | |
format compact | |
type solve2_3b.m | |
function C = solve2_3b(A) | |
size_of_A = size(A); | |
n = size_of_A(1,1); | |
format long, b = randi(10, n, 1) | |
x1 = A\b; | |
x2 = inv(A) * b; | |
x3 = rref([A b]); | |
x3 = x3(:,end); | |
C = [x1 x2 x3]; | |
n1 = norm(minus(x1,x2)); | |
n2 = norm(minus(x2,x3)); | |
n3 = norm(minus(x3,x1)); | |
format long, N = [n1; n2; n3] | |
format long, return | |
end | |
A = eye(4) | |
A = | |
1 0 0 0 | |
0 1 0 0 | |
0 0 1 0 | |
0 0 0 1 | |
solve2_3b(A) | |
b = | |
10 | |
1 | |
5 | |
2 | |
N = | |
0 | |
0 | |
0 | |
ans = | |
10 10 10 | |
1 1 1 | |
5 5 5 | |
2 2 2 | |
A = [4 0 -3 -7; -6 9 9 9; 7 -5 10 19; -1 2 4 -1] | |
A = | |
4 0 -3 -7 | |
-6 9 9 9 | |
7 -5 10 19 | |
-1 2 4 -1 | |
solve2_3b(A) | |
b = | |
10 | |
1 | |
8 | |
9 | |
N = | |
1.0e-04 * | |
0.000000000012864 | |
0.107253201187546 | |
0.107253201189822 | |
ans = | |
1.879740518962075 1.879740518962076 1.879746835443038 | |
0.486027944111777 0.486027944111776 0.486033519553073 | |
2.157185628742514 2.157185628742514 2.157181571815718 | |
-1.278942115768463 -1.278942115768462 -1.278947368421053 | |
format rat, A = hilb(4) | |
A = | |
1 1/2 1/3 1/4 | |
1/2 1/3 1/4 1/5 | |
1/3 1/4 1/5 1/6 | |
1/4 1/5 1/6 1/7 | |
solve2_3b(A) | |
b = | |
9 | |
1 | |
4 | |
3 | |
N = | |
1.0e-08 * | |
0.026824777352476 | |
0.108502270630065 | |
0.135298640136395 | |
ans = | |
1.0e+04 * | |
0.056399999999997 0.056399999999997 0.056400000000000 | |
-0.563999999999958 -0.563999999999966 -0.564000000000000 | |
1.277999999999893 1.277999999999915 1.278000000000000 | |
-0.797999999999929 -0.797999999999942 -0.798000000000000 | |
format rat, A = hilb(9) | |
A = | |
Columns 1 through 4 | |
1 1/2 1/3 1/4 | |
1/2 1/3 1/4 1/5 | |
1/3 1/4 1/5 1/6 | |
1/4 1/5 1/6 1/7 | |
1/5 1/6 1/7 1/8 | |
1/6 1/7 1/8 1/9 | |
1/7 1/8 1/9 1/10 | |
1/8 1/9 1/10 1/11 | |
1/9 1/10 1/11 1/12 | |
Columns 5 through 8 | |
1/5 1/6 1/7 1/8 | |
1/6 1/7 1/8 1/9 | |
1/7 1/8 1/9 1/10 | |
1/8 1/9 1/10 1/11 | |
1/9 1/10 1/11 1/12 | |
1/10 1/11 1/12 1/13 | |
1/11 1/12 1/13 1/14 | |
1/12 1/13 1/14 1/15 | |
1/13 1/14 1/15 1/16 | |
Column 9 | |
1/9 | |
1/10 | |
1/11 | |
1/12 | |
1/13 | |
1/14 | |
1/15 | |
1/16 | |
1/17 | |
solve2_3b(A) | |
b = | |
9 | |
5 | |
10 | |
2 | |
3 | |
2 | |
2 | |
9 | |
6 | |
N = | |
1.0e+06 * | |
0.936494341184876 | |
0.898756566857970 | |
1.835247069862893 | |
ans = | |
1.0e+11 * | |
-0.000044769736468 -0.000044769819727 -0.000044769900000 | |
0.003247289674963 0.003247295469302 0.003247301080000 | |
-0.056965195354481 -0.056965294082565 -0.056965389170000 | |
0.417857453320942 0.417858161017986 0.417858840890000 | |
-1.565823613786031 -1.565826221792047 -1.565828714810000 | |
3.253017755085654 3.253023069413168 3.253028189620000 | |
-3.789873542187753 -3.789879676017399 -3.789885543930000 | |
2.316924449955657 2.316928146955028 2.316931708410000 | |
-0.578383138780138 -0.578384064040321 -0.578384934110000 | |
% Since hilb is poorly conditioned it's very sensitive to round-off errors, | |
% ecspecially as the matrix size grows. | |
det(hilb(9)) | |
ans = | |
9.720278969918640e-43 | |
diary off |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment