2021-03-06 14:15:22 +01:00
|
|
|
clear all;
|
|
|
|
|
2021-03-07 22:56:18 +01:00
|
|
|
A = [2, -1, 0, 0;
|
2021-03-06 20:58:15 +01:00
|
|
|
-1, 2, -1, 0;
|
2021-03-07 22:56:18 +01:00
|
|
|
0, -1, 2, -1;
|
|
|
|
0, 0, -1, 2];
|
2021-03-06 14:15:22 +01:00
|
|
|
|
2021-03-06 18:17:36 +01:00
|
|
|
b = [0;0;0;5];
|
2021-03-06 14:15:22 +01:00
|
|
|
|
2021-03-13 13:42:56 +01:00
|
|
|
B = Alg1_outer_product_gaussian_elimination(A);
|
2021-03-07 22:56:18 +01:00
|
|
|
U = triu(B);
|
|
|
|
L = tril(B, -1);
|
|
|
|
x = back_substitution(U, b);
|
2021-03-06 18:17:36 +01:00
|
|
|
|
2021-03-07 22:56:18 +01:00
|
|
|
%% Problem 1
|
|
|
|
clear all;
|
|
|
|
A = [2, -1, 0, 0;
|
|
|
|
-1, 2, -1, 0;
|
|
|
|
0, -1, 2, -1;
|
|
|
|
0, 0, -1, 2];
|
|
|
|
|
|
|
|
b = [0;0;0;5];
|
|
|
|
|
|
|
|
B = gauss_jordan_elimination([A b])
|
|
|
|
|
2021-03-13 13:42:56 +01:00
|
|
|
[P, Q, L, U] = Alg2_gaussian_elimination_with_complete_pivoting(A);
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
b = P*b;
|
|
|
|
% Ly = b and Ux = y
|
|
|
|
y = forward_substitution(L, b);
|
|
|
|
|
|
|
|
x = Q*back_substitution(U, y);
|
|
|
|
|
|
|
|
% L*U
|
|
|
|
|
|
|
|
%% Problem 2
|
|
|
|
A = [1, 1, 1;
|
|
|
|
1, 1, 2;
|
|
|
|
1, 2, 2];
|
|
|
|
|
|
|
|
b = [1;2;1];
|
|
|
|
|
2021-03-13 13:42:56 +01:00
|
|
|
[P, Q, L, U] = Alg2_gaussian_elimination_with_complete_pivoting(A);
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
b = P*b;
|
|
|
|
% Ly = b and Ux = y
|
|
|
|
y = forward_substitution(L, b);
|
|
|
|
|
|
|
|
x = Q*back_substitution(U, y)
|
|
|
|
|
|
|
|
% L*U
|
|
|
|
|
|
|
|
|
|
|
|
%% 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-13 16:16:01 +01:00
|
|
|
B = Alg5_gauss_jordan_elimination([A b])
|
|
|
|
Bp = Alg5_gauss_jordan_elimination([A bp])
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
%% Problem 5
|
|
|
|
% AX = I3
|
|
|
|
A = [2, 1, 2;
|
|
|
|
1, 2, 3;
|
|
|
|
4, 1, 2];
|
|
|
|
|
2021-03-13 13:42:56 +01:00
|
|
|
[P, Q, L, U] = Alg2_gaussian_elimination_with_complete_pivoting(A);
|
2021-03-07 22:56:18 +01:00
|
|
|
|
|
|
|
I = P*eye(3);
|
|
|
|
% Ly = b and Ux = y
|
|
|
|
y = forward_substitution(L, I);
|
|
|
|
|
|
|
|
X = Q*back_substitution(U, y)
|
2021-03-13 13:42:56 +01:00
|
|
|
inv(A)
|
|
|
|
|
|
|
|
%% Problem 6
|
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])
|
|
|
|
|
|
|
|
|