-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2PartWithQR.m
85 lines (50 loc) · 1.96 KB
/
test2PartWithQR.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
%% SECONDA PARTE
% Grazie ai dati prestati dal docente, verifichiamo prima con risoluzione di
% un sistema con fattorizzazione QR, se riusciamo ad ottenere una N
% (superfici normali) di buona qualità.
%%
addpath Functions/
format short e
%ora ho L M N r s
%ottenere sistema L’ N = M’
Ltrasp = L';
Mtrasp = M';
%% con HouseHolder
tic
%fatt QR di Ltrasp risoluzione sist minimi quadrati QR
[Qh, Rh] = HouseHolderQR(Ltrasp);
Nqrtesth = QRSystemResolution(Qh, Rh, Mtrasp);
timeH = toc;
%% con Givens
%fatt QR di Ltrasp risoluzione sist minimi quadrati QR
tic
[Qg, Rg] = GivensQR(Ltrasp);
Nqrtestg = QRSystemResolution(Qg, Rg, Mtrasp);
timeG = toc;
%% matlab
tic
Nmatlab = Ltrasp\Mtrasp;
timeM = toc;
%% errore nella fattorizzazione - normale, householder, givens, matlab
disp('')
errFatt = [norm(N'*L-M, inf), norm(Nqrtesth'*L-M, inf), norm(Nqrtestg'*L-M, inf), norm(Nmatlab'*L-M, inf)];
%% errore assoluto sulle normali - normale, householder, givens, matlab
errN = [NaN, norm(N - Nqrtesth, inf), norm(N - Nqrtestg, inf), norm(N - Nmatlab, inf)];
%% errore relativo sulle normali - normale, householder, givens, matlab
errNRel = [NaN, (norm(N - Nqrtesth, inf)/ norm(N, inf)), (norm(N - Nqrtestg, inf)/ norm(N, inf)), (norm(N - Nmatlab, inf)/ norm(N, inf))];
% come se stessimo prendendo per buona quella di matlab
errNmathRel = [NaN, (norm(Nmatlab - Nqrtesth, inf) / norm(Nmatlab, inf)), (norm(Nmatlab - Nqrtestg, inf) / norm(Nmatlab, inf)), NaN];
%% salvataggio dei tempi
timeAll = [NaN, timeH, timeG, timeM];
%% creazione di una unica matrice (ogni colonna corrisponde ad un metodo)
date=[errFatt; errN; errNRel; errNmathRel; timeAll];
%% stampa
figure
title('Relative Error, Normals');
xlabel('Resolution Methods');
ylabel('Relative Error');
bar(categorical({'Householder', 'Givens', 'Matlab'}), [date(3, 2), date(3, 3), date(3, 4)]);
legend('error');
% preserve your memory lol
clear errFatt errN errNmath errNRel errNmathRel timeAll
clear timeH timeG timeM