-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_transpose_for_diff.m
79 lines (62 loc) · 1.96 KB
/
demo_transpose_for_diff.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
%% Reference
% 1) https://en.wikipedia.org/wiki/Inner_product_space
% 2) https://en.wikipedia.org/wiki/Transpose
% 3) https://en.wikipedia.org/wiki/Complex_conjugate
%% 1) Inner Product definition
% < X, Y > = < [x1; x2; ...; xn], [y1; y2; ...; yn] >
% = [x1; x2; ...; xn]' * [y1; y2; ...; yn]
% = SUM_(i=1)^(n) xi * yi
% = (x1 * y1) + (x2 * y2) + ... + (xn * yn)
%% 2) Transpose definition
% If, < A * X, Y > = < X, A^T * Y >
% then, A^T is A's transpose
%% 3) Complex conjugate definition
% (a + ib)' = a - ib;
%% Clear the Workspace
clear;
home;
%% Generate data A in R ^ ( N x M ), X in R ^ ( M x K ) and Y in R ^ ( N x K )
dataType = 'IMAG'; % dataType = [COMPLEX, REAL, IMAG]
N = 100;
M = N;
K = N;
A = @(x) Dx(x);
AT = @(y) Dxt(y);
switch dataType
case 'REAL'
X = rand(M, K);
Y = rand(N, K);
case 'IMAG'
X = 1i*rand(M, K);
Y = 1i*rand(N, K);
case 'COMPLEX'
X = rand(M, K) + 1i*rand(M, K);
Y = rand(N, K) + 1i*rand(N, K);
end
%% Calculate < A * X, Y >
% A * X
AX = A(X);
% < A * X, Y >
lhs = AX(:)'*Y(:);
%% Calculate < X, A^T * Y >
% A^T * Y
ATY = AT(Y);
% < X, A^T * Y >
rhs = X(:)'*ATY(:);
%% Proof that
% < A * X, Y > = < X, A^T * Y >
% < A * X, Y > - < X, A^T * Y > = 0
th = 1e-10;
disp(['dim( A ) = ' dataType ' ^ ' num2str([N, M], '( %d, %d )')]);
disp(['dim( X ) = ' dataType ' ^ ' num2str([M, K], '( %d, %d )')]);
disp(['dim( Y ) = ' dataType ' ^ ' num2str([N, K], '( %d, %d )')]);
disp(' ');
disp([' < A * X, Y > = ' num2str(lhs, '%.6f') ]);
disp([' < X, A^T * Y > = ' num2str(rhs, '%.6f') ]);
disp([' < A * X, Y > - < X, A^T * Y > = ' num2str(lhs - rhs, '%.6f') ]);
disp(' ');
if (abs(lhs - rhs) < th)
disp(['Since < A * X, Y > = < X, A^T * Y >, A^T is the Transpose of A.']);
else
disp(['Since < A * X, Y > != < X, A^T * Y >, A^T is not the Transpose of A.']);
end