2021-03-07 22:56:18 +01:00
|
|
|
%% Problem 1
|
|
|
|
clear all;
|
2021-03-21 19:45:18 +01:00
|
|
|
clc;
|
2021-03-07 22:56:18 +01:00
|
|
|
A = [2, -1, 0, 0;
|
|
|
|
-1, 2, -1, 0;
|
|
|
|
0, -1, 2, -1;
|
|
|
|
0, 0, -1, 2];
|
|
|
|
b = [0;0;0;5];
|
2021-03-21 19:45:18 +01:00
|
|
|
B = Alg5([A b])
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
%% Problem 2
|
2021-03-21 19:45:18 +01:00
|
|
|
clear all;
|
|
|
|
clc;
|
2021-03-07 22:56:18 +01:00
|
|
|
A = [1, 1, 1;
|
|
|
|
1, 1, 2;
|
|
|
|
1, 2, 2];
|
|
|
|
b = [1;2;1];
|
|
|
|
|
2021-03-21 19:45:18 +01:00
|
|
|
[P, Q, L, U] = Alg2(A);
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
b = P*b;
|
|
|
|
% Ly = b and Ux = y
|
2021-03-21 19:45:18 +01:00
|
|
|
y = Alg3(L, b); % Forward substitution
|
|
|
|
x = Q*Alg4(U, y) % Backward substitution
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
%% Problem 4
|
|
|
|
|
|
|
|
A = [0.835, 0.667;
|
|
|
|
0.333, 0.266];
|
|
|
|
b = [0.168; 0.067];
|
|
|
|
bp = [0.168; 0.066];
|
|
|
|
|
|
|
|
kappa = cond(A)
|
|
|
|
|
2021-03-21 19:45:18 +01:00
|
|
|
B = Alg5([A b])
|
|
|
|
Bp = Alg5([A bp])
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
%% Problem 5
|
2021-03-21 19:45:18 +01:00
|
|
|
clear all;
|
|
|
|
clc;
|
2021-03-07 22:56:18 +01:00
|
|
|
A = [2, 1, 2;
|
|
|
|
1, 2, 3;
|
|
|
|
4, 1, 2];
|
|
|
|
|
2021-03-21 19:45:18 +01:00
|
|
|
[P, Q, L, U] = Alg2(A)
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
I = P*eye(3);
|
|
|
|
% Ly = b and Ux = y
|
2021-03-21 19:45:18 +01:00
|
|
|
y = Alg3(L, I); % Forward substitution
|
|
|
|
x = Q*Alg4(U, y) % Backward substitution
|
|
|
|
inv(A) - x
|
2021-03-13 13:42:56 +01:00
|
|
|
|
|
|
|
%% Problem 6
|
2021-03-21 19:45:18 +01:00
|
|
|
clc;
|
|
|
|
|
|
|
|
A = [1 2 3 4;
|
|
|
|
-1 1 2 1;
|
|
|
|
0 2 1 3;
|
|
|
|
0 0 1 1];
|
|
|
|
|
|
|
|
[L, U, P] = Alg8(A)
|
|
|
|
det(A) - prod(diag(U))
|
2021-03-13 16:16:01 +01:00
|
|
|
|
|
|
|
%% Problem 10
|
|
|
|
|
|
|
|
% A = [1 2 2 3 1;
|
|
|
|
% 2 4 4 6 2;
|
|
|
|
% 3 6 6 9 6;
|
|
|
|
% 1 2 4 5 3]
|
|
|
|
|
|
|
|
A = [0.835, 0.667;
|
|
|
|
0.333, 0.266];
|
|
|
|
b = [0.168; 0.067];
|
|
|
|
|
|
|
|
Alg6_RREF([A b])
|
|
|
|
|
|
|
|
|