📄 test_mpoly_symbolic.m
字号:
end
HS = H*S;
[Q,method] = mldivide(H,HS);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 1)
warning('this should have been method 1');
end
disp('OK - multiplication/division: method 1 part 2, symbolic variable');
% projection factor
% case 1: F numeric
U = [3/5;4/5];
F = mpoly({eye(size(U,1)) - U*U',U*U'},0,'polyphase',2,1);
NF = N*F;
[Q,method] = mrdivide(NF,F);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
SF = S*F;
[Q,method] = mrdivide(SF,F);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
FN = F*N;
[Q,method] = mldivide(F,FN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
FS = F*S;
[Q,method] = mldivide(F,FS);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
disp('OK - multiplication/division: method 2, numeric');
% case 2: F symbolic constant
F = sym(F);
NF = N*F;
[Q,method] = mrdivide(NF,F);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
SF = S*F;
[Q,method] = mrdivide(SF,F);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
FN = F*N;
[Q,method] = mldivide(F,FN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
FS = F*S;
[Q,method] = mldivide(F,FS);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
disp('OK - multiplication/division: method 2, symbolic constant');
% case 3: F symbolic variable
U = [a;b]/sqrt(a^2+b^2);
F = mpoly({eye(size(U,1)) - U*U',U*U'},0,'polyphase',2,1);
NF = N*F;
[Q,method] = mrdivide(NF,F);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
SF = S*F;
[Q,method] = mrdivide(SF,F);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
FN = F*N;
[Q,method] = mldivide(F,FN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
FS = F*S;
[Q,method] = mldivide(F,FS);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 2)
warning('this should have been method 2');
end
disp('OK - multiplication/division: method 2, symbolic variable');
% upper triangular matrix
% I have to use a 3x3 example to force method 3
U = [1,1,1;0,1,1;0,0,0];
U(:,:,2) = [0,0,0;0,1,0;0,0,1];
U = mpoly(U);
% case 1: U numeric
R = [112,122,132;212,222,232;312,322,332];
R(:,:,2) = [113,123,133;213,223,233;313,323,333];
R = mpoly(R,2);
N = sym(R);
S = N;
S(1,1) = S(1,1)*a;
NU = N*U;
[Q,method] = mrdivide(NU,U);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
SU = S*U;
[Q,method] = mrdivide(SU,U);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
UN = U*N;
[Q,method] = mldivide(U,UN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
US = U*S;
[Q,method] = mldivide(U,US);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
disp('OK - multiplication/division: method 3 part 1, numeric');
% case 2: U symbolic constant
U = sym(U);
NU = N*U;
[Q,method] = mrdivide(NU,U);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
SU = S*U;
[Q,method] = mrdivide(SU,U);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
UN = U*N;
[Q,method] = mldivide(U,UN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
US = U*S;
[Q,method] = mldivide(U,US);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
disp('OK - multiplication/division: method 3 part 1, symbolic constant');
% case 3: U symbolic variable
U(1,1) = b;
NU = N*U;
[Q,method] = mrdivide(NU,U);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
SU = S*U;
[Q,method] = mrdivide(SU,U);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
UN = U*N;
[Q,method] = mldivide(U,UN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
US = U*S;
[Q,method] = mldivide(U,US);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
disp('OK - multiplication/division: method 3 part 1, symbolic variable');
% lower triangular matrix
% I have to use a 3x3 example to force method 3
U = [1,1,1;0,1,1;0,0,0]';
U(:,:,2) = [0,0,0;0,1,0;0,0,1]';
U = mpoly(U);
% case 1: U numeric
R = [112,122,132;212,222,232;312,322,332];
R(:,:,2) = [113,123,133;213,223,233;313,323,333];
R = mpoly(R,2);
N = sym(R);
S = N;
S(1,1) = S(1,1)*a;
NU = N*U;
[Q,method] = mrdivide(NU,U);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
SU = S*U;
[Q,method] = mrdivide(SU,U);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
UN = U*N;
[Q,method] = mldivide(U,UN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
US = U*S;
[Q,method] = mldivide(U,US);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
disp('OK - multiplication/division: method 3 part 2, numeric');
% case 2: U symbolic constant
U = sym(U);
NU = N*U;
[Q,method] = mrdivide(NU,U);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
SU = S*U;
[Q,method] = mrdivide(SU,U);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
UN = U*N;
[Q,method] = mldivide(U,UN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
US = U*S;
[Q,method] = mldivide(U,US);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
disp('OK - multiplication/division: method 3 part 2, symbolic constant');
% case 3: U symbolic variable
U(1,1) = b;
NU = N*U;
[Q,method] = mrdivide(NU,U);
if (Q ~= N)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
SU = S*U;
[Q,method] = mrdivide(SU,U);
if (Q ~= S)
error(['failed - right multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
UN = U*N;
[Q,method] = mldivide(U,UN);
if (Q ~= N)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
US = U*S;
[Q,method] = mldivide(U,US);
if (Q ~= S)
error(['failed - left multiplication or division, method ',num2str(method)]);
end
if (method ~= 3)
warning('this should have been method 3');
end
disp('OK - multiplication/division: method 3 part 2, symbolic variable');
U = [1,1;0,0];
U(:,:,2) = [0,0;0,1];
U = mpoly(U,1);
Uinv = inv(U);
if (Uinv * U ~= eye(2))
error('failed - inv');
end
Uinv = longinv(U);
if (Uinv * U ~= eye(2))
error('failed - longinv');
end
if (P^2 ~= P*P)
error('failed - mpower');
end
disp('OK - multiplication/division: mltimes, mldivide, mrtimes');
disp(' mrdivide, mpower, inv, longinv');
% test transpose
Pt = mpoly({P3',P2'},-3);
Prt = mpoly({P2',P3'},2);
if (P' ~= Pt)
error('failed - ctranspose');
end
if (P.' ~= Prt)
error('failed - transpose');
end
if ((P').' ~= reverse(P))
error('failed - reverse');
end
disp('OK - transpose, ctranspose, reverse');
% test rounding
if (ceil(N - 0.1) ~= N)
error('failed - ceil');
end
if (floor(N + 0.1) ~= N)
error('failed - floor');
end
if (fix(N * 1.000001) ~= N)
error('failed - fix');
end
if (round(N * 1.000001) ~= N)
error('failed - round');
end
disp('OK - rounding: ceil, floor, round, fix');
% test diagonal/triangle
if (N ~= (diag(N) + tril(N,-1) + triu(N,1)))
error('failed - diag, tril or triu');
end
if (S ~= (diag(S) + tril(S,-1) + triu(S,1)))
error('failed - diag, tril or triu');
end
disp('OK - diag, tril, triu');
% test determinant
U = [a;b]/sqrt(a^2+b^2);
F = mpoly({eye(size(U,1)) - U*U',U*U'},0,'polyphase',2,1);
if (det(F) ~= z)
error('failed - det')
end
disp('OK - det');
% test moment
if (moment(P) ~= P2+P3 | moment(P,1) ~= 2*P2+3*P3)
error('failed - moment');
end
disp('OK - moment');
% test match_type
Q = P * PP;
R = PP * symbol(PP);
if (~strcmp(Q.type,'polyphase') | ~strcmp(R.type,''))
error('failed - match_type');
end
disp('OK - match_type');
% test kron
Q = kron(P,P);
if (Q(3:4,1:2) ~= P(2,1)*P)
error('failed - kron');
end
disp('OK - kron');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -