-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpB.m
83 lines (66 loc) · 2.74 KB
/
ExpB.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
% Hitung Waktu Eksekusi dan Condition Number untuk setiap kasus uji
% Kelompok 1 - Kelas B
% Ukuran matriks N yang akan diuji
N_values = [16, 64, 128, 256, 512, 1000];
% Konfigurasi bandwidth (p, q)
bandwidths = {[1, 1]};
% Inisialisasi tabel hasil untuk waktu eksekusi dan condition number
results_blocktm_time = zeros(length(N_values), length(bandwidths));
results_block_time = zeros(length(N_values), length(bandwidths));
results_recursive_time = zeros(length(N_values), length(bandwidths));
condition_numbers = zeros(length(N_values), length(bandwidths));
% Loop melalui ukuran N
for i = 1:length(N_values)
N = N_values(i);
% Loop melalui setiap konfigurasi bandwidth (p, q)
for j = 1:length(bandwidths)
pq = bandwidths{j};
p = pq(1);
q = pq(2);
% Generate matriks banded untuk N dan (p, q)
A = BandMat(N, p, q);
% Generate vektor b secara acak
b = rand(N, 1);
% Hitung condition number sekali untuk tiap (N, p, q)
kondA = norm(A) * norm(inv(A));
condition_numbers(i, j) = kondA;
% --- Faktorisasi dan Penyelesaian SPL dengan BlockTM ---
tic;
[L_blocktm, U_blocktm] = BlockTM(A); % Faktorisasi LU dengan BlockTM
y_blocktm = BackSubs(L_blocktm, b); % Backward substitution untuk y
x_blocktm = BackSubs(U_blocktm, y_blocktm); % Backward substitution untuk x
exec_time_blocktm = toc;
% Simpan hasil waktu eksekusi untuk LU BlockTM
results_blocktm_time(i, j) = exec_time_blocktm;
% --- Faktorisasi dan Penyelesaian SPL dengan Block ---
tic;
[L_block, U_block] = Block(A); % Faktorisasi LU Block
y_block = BackSubs(L_block, b); % Backward substitution untuk y
x_block = BackSubs(U_block, y_block); % Backward substitution untuk x
exec_time_block = toc;
% Simpan hasil waktu eksekusi untuk LU Block
results_block_time(i, j) = exec_time_block;
% Tampilkan hasil sementara
fprintf('N = %d, p = %d, q = %d\n', N, p, q);
fprintf('BlockTM Time: %.6f, Block Time: %.6f\n', exec_time_blocktm, exec_time_block);
fprintf('Condition Number: %.6f\n\n', kondA);
end
end
% Tampilkan hasil waktu eksekusi dalam format tabel untuk Block
disp('Waktu Eksekusi (dalam detik) Block');
fprintf('N \t\t (1, 1)\n');
for i = 1:length(N_values)
fprintf('%d \t\t %.6f\n', N_values(i), results_block_time(i, 1));
end
% Tampilkan hasil waktu eksekusi dalam format tabel untuk Block TM
disp('Waktu Eksekusi (dalam detik) Block TM');
fprintf('N \t\t (1, 1)\n');
for i = 1:length(N_values)
fprintf('%d \t\t %.6f\n', N_values(i), results_blocktm_time(i, 1));
end
% Tampilkan hasil condition number dalam format tabel
disp('Condition Number');
fprintf('N \t\t (1, 1)\n');
for i = 1:length(N_values)
fprintf('%d \t\t %.6f\n', N_values(i), condition_numbers(i, 1));
end