Created
September 20, 2016 11:47
-
-
Save DiamondLovesYou/350b29b48ad6b1638ccb1725e83d63a8 to your computer and use it in GitHub Desktop.
This file contains 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
A = [ | |
0.172 0.013 0.144; | |
0.368 0.681 0.271; | |
0.099 0.510 0.329; | |
]; | |
[A2, success, pivots, cond_num] = Factor(A); | |
assert(success == 0, 'failed to factor A'); | |
b = [ | |
1.44 4.35 1.32 3.95; | |
2.84 9.30 2.90 8.29; | |
2.36 3.45 3.25 7.35; | |
]; | |
[m,n] = size(b); | |
x = zeros(m, n); | |
for i = 1:n | |
out = Solve(A2, pivots, b(:,i)); | |
x(:,i) = out; | |
end | |
fprintf(' part a)\n'); | |
x | |
fprintf('norm(x, Inf) = %d\n', norm(x, Inf)); | |
fprintf('condition number = %d\n', cond_num); | |
fprintf('\nAssuming exact data =>\n'); | |
fprintf('u = %d\n', eps()); | |
rel_err_bnd = (cond_num / (1 - cond_num * 10 * eps())) * (10 * eps()); | |
fprintf('absolute error bound = %d\n', rel_err_bnd * norm(x, Inf)); | |
fprintf('Remarks: very low error bound, much lower than the condition number.\n'); | |
fprintf('\n'); | |
fprintf('Assuming rounded data =>\n'); | |
u_a = 10^(-2); | |
u_b = u_a; | |
fprintf('u_a = %d, u_b = %d\n', u_a, u_b); | |
rel_err_bnd = (cond_num / (1 - cond_num * 10 * u_a)) * (10 * u_a + 10 * u_b); | |
fprintf('absolute error bound = %d\n', rel_err_bnd * norm(x, Inf)); | |
fprintf('Remarks: the absolute error bound is much\n\tgreater than the condition number.\n'); | |
fprintf('\n part b)\n'); | |
A_inv = zeros(m, m); | |
for i = 1:m | |
b = zeros(m, 1); | |
b(i, 1) = 1.0; | |
out = Solve(A2, pivots, b); | |
A_inv(:,i) = out; | |
end | |
A_inv | |
fprintf('exact cond(A) = %d\n', norm(A_inv, Inf) * norm(A, Inf)); |
This file contains 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
format long e | |
Exercise2_17 | |
part a) | |
x = | |
3.140783569018794e+00 2.237596248442763e+01 2.146024337702900e-01 7.050291746699174e+00 | |
-1.394314816153835e-02 1.860712214737706e-01 6.188937759548281e-01 8.285203102998583e-01 | |
6.249767271214358e+00 3.464691158328394e+00 8.854463627111791e+00 1.893457677454059e+01 | |
norm(x, Inf) = 3.750350e+01 | |
condition number = 6.061168e+00 | |
Assuming exact data => | |
u = 2.220446e-16 | |
absolute error bound = 5.047407e-13 | |
Remarks: very low error bound, much lower than the condition number. | |
Assuming rounded data => | |
u_a = 1.000000e-02, u_b = 1.000000e-02 | |
absolute error bound = 1.154226e+02 | |
Remarks: the absolute error bound is much | |
greater than the condition number. | |
part b) | |
A_inv = | |
2.781856394194422e+00 2.241423290015830e+00 -3.063869399265308e+00 | |
-3.054211863582577e+00 1.371888592353571e+00 2.067620055564530e-01 | |
3.897398989063425e+00 -2.801106649884160e+00 3.640955768065272e+00 | |
exact cond(A) = 1.364809e+01 | |
diary off |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment