Commit 3582a6b7 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

some minor performance adjustments

parent 7a775ad3
......@@ -27,27 +27,4 @@ warning('DEPRICATED: Use polyMatrix.polynomial2coefficients instead')
% >> ans(:,:,4) = [ 0, 0]
% [ 0, 3]
% -------------------------------------------------------------------------
import misc.*
if ~exist('N', 'var')
% determine maximal degree of spatial variable s
sDegreeMax = -1;
for i=1:numel(A)
sDegreeMax = max([sDegreeMax, length(coeffsAll(A(i),s_var))]);
end
N=sDegreeMax;
end
% convert system-operator into polynomal expression
APoly = sym(zeros([size(A), N]));
for i=1:size(A,1)
for j=1:size(A,2)
tmp = coeffsAll(A(i,j), s_var);
for k=1:N
if k>length(tmp)
APoly(i, j, k) = sym(0);
else
APoly(i, j, k) = sym(tmp(k));
end
end
end
end
\ No newline at end of file
[ APoly ] = polyMatrix.polynomial2coefficients(A, s_var, N);
\ No newline at end of file
......@@ -26,27 +26,21 @@ function [ APoly ] = polynomial2coefficients(A, s_var, N)
% >> ans(:,:,4) = [ 0, 0]
% [ 0, 3]
% -------------------------------------------------------------------------
import misc.*
if ~exist('N', 'var')
% determine maximal degree of spatial variable s
sDegreeMax = -1;
for i=1:numel(A)
sDegreeMax = max([sDegreeMax, length(coeffsAll(A(i),s_var))]);
sDegreeMax = max([sDegreeMax, length(coeffs(A(i), s_var, 'All'))]);
end
N=sDegreeMax;
end
% convert system-operator into polynomal expression
APoly = sym(zeros([size(A), N]));
APoly = zeros([size(A), N]);
for i=1:size(A,1)
for j=1:size(A,2)
tmp = coeffsAll(A(i,j), s_var);
for k=1:N
if k>length(tmp)
APoly(i, j, k) = sym(0);
else
APoly(i, j, k) = sym(tmp(k));
end
end
tmp = flip( coeffs(A(i,j), s_var, 'All') );
APoly(i, j, 1:numel(tmp)) = tmp;
end
end
\ No newline at end of file
......@@ -1694,15 +1694,25 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
function objT = transpose(obj)
objT = builtin('transpose', copy(obj));
objT.setName("{" + obj(1).name + "}^{T}");
if ~isempty(obj)
objT.setName("{" + obj(1).name + "}^{T}");
else
objT.setName("{.}^{T}");
end
end % transpose(obj)
function objCt = ctranspose(obj)
objT = obj.';
objCtMat = conj(objT.on());
objCt = quantity.Discrete(objCtMat, ...
'domain', obj(1).domain, ...
'name', "{" + obj(1).name + "}^{H}");
if ~isempty(objT)
objCtMat = conj(objT.on());
objCt = quantity.Discrete(objCtMat, ...
'domain', obj(1).domain, ...
'name', "{" + obj(1).name + "}^{H}");
else
objCt = objT;
end
end % ctranspose(obj)
function y = exp(obj)
......
......@@ -193,14 +193,14 @@ classdef PolynomialOperator < handle & matlab.mixin.Copyable
C = A + (-1)*B;
end
function C = adj(A)
assert(A(1).coefficient.isConstant())
function C = adj(obj)
assert(obj(1).coefficient.isConstant())
C = polyMatrix.polynomial2coefficients(misc.adj(sym( A )), A(1).s);
C = polyMatrix.polynomial2coefficients(misc.adj(sym( obj )), obj(1).s);
c = cell(1, size(C, 3));
for k = 1:size(C, 3)
c{k} = quantity.Discrete(double(C(:,:,k)), ...
'gridName', {}, 'grid', {}, 'name', "adj(" + A(1).coefficient(1).name + ")");
'gridName', {}, 'grid', {}, 'name', "adj(" + obj(1).coefficient(1).name + ")");
end
C = signals.PolynomialOperator(c);
......@@ -227,7 +227,11 @@ classdef PolynomialOperator < handle & matlab.mixin.Copyable
function s = size(obj, varargin)
s = [length(obj), size(obj(1).coefficient)];
s = s(varargin{:});
if nargin > 1
s = s(varargin{:});
end
end
function l = length(obj)
......
......@@ -19,3 +19,26 @@ function cTransposeTest(testCase)
testCase.verifyEqual(K(:,:,2)', -KT(:,:,2))
end
function polynomial2coefficientsTest(testCase)
syms s;
A0 = rand(2);
A1 = rand(2);
A2 = rand(2);
A3 = rand(2);
A = A0 + A1*s + A2*s^2 + A3*s^3;
Ac = double( polyMatrix.polynomial2coefficients(A, s) );
testCase.verifyEqual(Ac(:,:,1), A0);
testCase.verifyEqual(Ac(:,:,2), A1);
testCase.verifyEqual(Ac(:,:,3), A2);
testCase.verifyEqual(Ac(:,:,4), A3);
a = s^5;
ac = double( polyMatrix.polynomial2coefficients(a,s) );
testCase.verifyEqual(ac(:), misc.unitVector(6,6));
end
......@@ -52,11 +52,12 @@ end % testProd()
function testHashData(testCase)
spatialDomain = quantity.Domain("z", linspace(0, 1, 101));
L1 = quantity.Symbolic(diag([2, -3]), ...
'domain', spatialDomain, 'name', 'Lambda');
spatialDomain = quantity.Domain("z", linspace(0, 1, 11));
M1 = reshape(repmat(diag([2, -3]), spatialDomain.n, 1, 1), spatialDomain.n, 2, 2);
L1 = quantity.Discrete(M1, 'domain', spatialDomain, 'name', 'Lambda');
L2 = quantity.Symbolic(diag([1, -1]), ...
M2 = reshape(repmat(diag([1, -1]), spatialDomain.n, 1, 1), spatialDomain.n, 2, 2);
L2 = quantity.Discrete(M2, ...
'domain', spatialDomain, 'name', 'Lambda');
testCase.verifyNotEqual(L1.hash, L2.hash);
......@@ -281,6 +282,12 @@ tc.verifyEqual(qDiscrete(1,1).on(), qDiscreteTransp(1,1).on());
tc.verifyEqual(qDiscrete(2,2).on(), qDiscreteTransp(2,2).on());
tc.verifyEqual(qDiscrete(1,2).on(), qDiscreteTransp(2,1).on());
tc.verifyEqual(qDiscrete(2,1).on(), qDiscreteTransp(1,2).on());
E = qDiscrete * ones(2,0);
tc.verifyEqual( size(E'), size( ( ones(size(qDiscrete)) * ones(2,0) )' ))
tc.verifyEqual( size(E.'), size( ( ones(size(qDiscrete)) * ones(2,0) )' ))
end % testTranspose
function testFlipGrid(tc)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment