-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_matrixEquationSolver.m
51 lines (39 loc) · 1.07 KB
/
test_matrixEquationSolver.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
function pass = test_matrixEquationSolver()
% Test matrixEquationSolver.m
tol = 1e-8;
n = 10;
m = 12;
%% Test 1
A = randn( n ) + 1i*randn(n);
B = randn( m ) + 1i*randn(m);
EXACT = randn( n, m);
F = A * EXACT * B.';
X = matrixEquationSolver({A}, {B}, F);
pass(1) = ( norm( X - EXACT ) < tol );
%% Test 2
C = randn( n ) + 1i*randn(n);
D = randn( m ) + 1i*randn(m);
EXACT = randn( n, m);
F = A * EXACT * B.' + C * EXACT * D.';
X = matrixEquationSolver({A,C}, {B,D}, F);
pass(2) = ( norm( X - EXACT ) < tol );
%% Test 3
E = randn( n ) + 1i*randn(n) ;
G = randn( m ) + 1i*randn(m);
EXACT = randn( n, m);
F = A * EXACT * B.' + C * EXACT * D.' + E * EXACT * G.';
X = matrixEquationSolver({A,C,E}, {B,D,G}, F);
pass(3) = ( norm( X - EXACT ) < tol );
%% Test 4
K = 10; % number of terms:
EXACT = randn( n, m );
F = zeros( n, m );
A = cell(K,1); B = cell(K,1);
for j = 1:K
A{j} = randn( n ) + 1i*randn( n );
B{j} = randn( m ) + 1i*randn( m );
F = F + A{j} * EXACT * B{j}.';
end
X = matrixEquationSolver(A, B, F);
pass(4) = ( norm( X - EXACT ) < tol );
end