-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRDecomposition.m
113 lines (77 loc) · 2.96 KB
/
QRDecomposition.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
%% Numerical Regrouping using a QR decomposition
% Algorithm based on :
% Gautier et al. "Numerical calculation of the base inertial parameters of robots", 1990
% the inputs are the Observation Matrix which consists of multiple Regressor
% Matrices Y : [Y1, Y2, ..., Ynt]^T with 1...nt measurements
% and the Inertial Parameters InParam as symbolic variables.
% Inputs:
% ObservationMatrix: dimension: nq*nt x p , type : double
% Outputs:
% Selection-matrices Aid and Ad (can be used by multiplication on the Observation matrix and Inertial parameter vector, to get the independent (Aid) or dependent (Ad) parts)
% beta are the regrouped parameters or base inertial parameters
% Inverse mapping Ginv (InParam = Ginv*[beta; zeros(dim_d,1)])
% dim_id and dim_d are dimension of the independent and dependent parameter vectors
% Kd is a matrix used for computing Ginv and beta.
% Note:
% usually the dependent inertial parameters are set to zero because of
% simplicity and to get a solution for the regrouped parameters
% beta.
% Author: Daniel Haugk, 2024, University of Michigan
function [Aid, Ad, Kd, beta, Ginv, dim_id, dim_d] = QRDecomposition(ObservationMatrix,InParam)
% assign Observation matrix to variable
W = ObservationMatrix;
% get number of parameters
[~, p] = size(W);
% get permutation vector M which contains the index of each independant column (Parameter) as its first "rankW" elements
[~, ~, M] = qr(W,0);
% rank estimation
rankW = rank(W);
% get index of each independant parameter and sort them
idx=sort(M(1:rankW));
% get each index of dependant columns (Parameters), by checking which elements are in the independant index set
j = 1;
for i = 1:p
if ~ismember(i,idx)
idx_(j) = i;
j = j + 1;
end
end
% sort dependant index set
idx_ = sort(idx_);
% intialize selection matrices
Aid = zeros(p,rankW);
Ad = zeros(p,p-rankW);
% get selection matrix for indepenant parameters
for i = 1:rankW
Aid(idx(i),i) = 1;
end
% get selection matrix for dependant parameters
for i = 1:p-rankW
Ad(idx_(i),i) = 1;
end
% combine both selection matrix to get full selection matrix
A = [Aid Ad];
% get QR-decomposition matrix R for computation of Kd (see Gautier paper)
[~ , R_] = qr(W*A);
% split R matrix into an indepant and dependant part
R1 = R_(1:rankW,1:rankW);
R2 = R_(1:rankW,rankW+1:end);
% compute Kd
Kd = R1\R2;
% get rid of extremely small numbers for more numerical stability
Kd(abs(Kd)<sqrt(eps)) = 0;
% get independant parameters
pi_id = Aid.'*InParam;
% get dependant parameters
pi_d = Ad.'*InParam;
% compute matrix for G/Ginv
KG_ = [eye(length(pi_id)) -Kd; zeros(length(pi_d),length(pi_id)) eye(length(pi_d))];
% compute base inertial parameters
beta = pi_id + Kd*pi_d;
% compute Ginv
Ginv = A*KG_;
% dimension of independant parameters
dim_id = length(pi_id);
% dimension of dependant parameters
dim_d = length(pi_d);
end