Commit 23f7b3e4 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete and .Symbolic :

- setName() for setting names of all elements of a quantity array
- transpose() for transposing quantities: now call by value and change of name
- flipGrid() changes name now
parent 80d06b61
......@@ -238,6 +238,11 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
error('Not yet implemented')
end
end
function setName(obj, newName)
% Function to set all names of all elements of the quantity obj to newName.
[obj.name] = deal(newName);
end % setName()
end
methods (Access = public)
......@@ -1038,6 +1043,10 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
end
function b = flipGrid(a, myGridName)
% flipGrid() implements a flip of the grids, for example with a(z)
% b(z) = a(1-z) = a.flipGrid('z');
% or for the multidimensional case with c(z, zeta)
% d(z, zeta) = c(1-z, 1-zeta) = c.flipGrid({'z', 'zeta'});
bMat = a.on();
if ~iscell(myGridName)
myGridName = {myGridName};
......@@ -1048,7 +1057,7 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
end
b = quantity.Discrete(bMat, ...
'grid', a(1).grid, 'gridName', a(1).gridName, ...
'name', [a(1).name]);
'name', ['flip(', a(1).name, ')']);
end % flipGrid()
function newObj = changeGrid(obj, gridNew, gridNameNew)
......@@ -1352,11 +1361,23 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
y = quantity.Discrete(reshape(invDiscrete, size(objDiscreteOriginal)),...
'size', size(obj), ...
'name', ['(', obj(1).name, ')^{-1}'], ...
'name', ['{(', obj(1).name, ')}^{-1}'], ...
'grid', obj(1).grid, 'gridName', obj(1).gridName);
end
end % inv()
function objT = transpose(obj)
objT = builtin('transpose', copy(obj));
[objT.name] = deal(['{', obj(1).name, '}^{T}']);
end % transpose(obj)
% function objCt = ctranspose(obj)
% objT = obj.';
% objCtMat = conj(objT.on());
% objCt = quantity.Discrete(objCtMat, 'grid', obj(1).grid, ...
% 'gridName', obj(1).gridName, 'name', ['{', obj(1).name, '}^{H}']);
% end % ctranspose(obj)
function y = exp(obj)
% exp() is the exponential function using obj as the exponent.
y = quantity.Discrete(exp(obj.on()), ...
......@@ -2101,6 +2122,7 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
% quantity.Discrete class.
permuteGrid = [idxGrid(lGridA), idxGrid(lGridB), idxGrid(lGridVA), idxGrid(lGridVB)];
end
function f = setValueContinuous(obj, f)
end
......
......@@ -486,7 +486,7 @@ classdef Symbolic < quantity.Function
end
b = quantity.Symbolic(subs(a.sym, variableOld, variableNew), ...
'grid', a(1).grid, 'variable', a(1).variable, ...
'name', a(1).name);
'name', ['flip(', a(1).name, ')']);
end % flipGrid()
function thisVariable = gridName2variable(obj, thisGridName)
......
......@@ -4,6 +4,38 @@ function [tests] = testDiscrete()
tests = functiontests(localfunctions);
end
function testTranspose(tc)
syms z zeta
qSymbolic = quantity.Symbolic(...
[1+z*zeta, -zeta; -z, z^2], 'grid', {linspace(0, 1, 21), linspace(0, 1, 41)},...
'variable', {z, zeta}, 'name', 'q');
qDiscrete = quantity.Discrete(qSymbolic);
qDiscreteTransp = qDiscrete.';
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());
end % testTranspose
% function testCtranspose(tc)
% syms z zeta
% qSymbolic = quantity.Symbolic(...
% [1+z*zeta, -zeta; -z, z^2], 'grid', {linspace(0, 1, 21), linspace(0, 1, 41)},...
% 'variable', {z, zeta}, 'name', 'q');
% qDiscrete = quantity.Discrete(qSymbolic);
% qDiscreteCtransp = qDiscrete';
% tc.verifyEqual(qDiscrete(1,1).on(), qDiscreteCtransp(1,1).on());
% tc.verifyEqual(qDiscrete(2,2).on(), qDiscreteCtransp(2,2).on());
% tc.verifyEqual(qDiscrete(1,2).on(), qDiscreteCtransp(2,1).on());
% tc.verifyEqual(qDiscrete(2,1).on(), qDiscreteCtransp(1,2).on());
%
% qDiscrete2 = quantity.Discrete(ones(11, 1) + 2i, ...
% 'grid', linspace(0, 1, 11), 'gridName', 'z', 'name', 'im');
% qDiscrete2Ctransp = qDiscrete2';
% tc.verifyEqual(qDiscrete2.real.on(), qDiscrete2Ctransp.real.on());
% tc.verifyEqual(qDiscrete2.imag.on(), -qDiscrete2Ctransp.imag.on());
% end % testTranspose
function testFlipGrid(tc)
syms z zeta
myGrid = linspace(0, 1, 11);
......@@ -22,7 +54,6 @@ fFlipped2 = f.flipGrid({'z', 'zeta'});
fFlipped3 = f.flipGrid({'zeta', 'z'});
tc.verifyEqual(fReference2.on(), fFlipped2.on(), 'AbsTol', 10*eps);
tc.verifyEqual(fReference2.on(), fFlipped3.on(), 'AbsTol', 10*eps);
end % testFlipGrid();
function testScalarPlusMinusQuantity(testCase)
......@@ -32,7 +63,7 @@ f = quantity.Discrete(quantity.Symbolic([1; 2] + zeros(2, 1)*z, ...
'variable', {z}, 'grid', {myGrid}));
testCase.verifyError(@() 1-f-1, '');
testCase.verifyError(@() 1+f+1, '');
end
end % testScalarPlusMinusQuantity
function testNumericVectorPlusMinusQuantity(testCase)
syms z
......@@ -44,7 +75,7 @@ testCase.verifyEqual(on(a-f), 1-f.on());
testCase.verifyEqual(on(f-a), f.on()-1);
testCase.verifyEqual(on(a+f), f.on()+1);
testCase.verifyEqual(on(f+a), f.on()+1);
end
end % testNumericVectorPlusMinusQuantity
function testUnitaryPluasAndMinus(testCase)
syms z zeta
......
......@@ -4,6 +4,35 @@ function [tests ] = testSymbolic()
tests = functiontests(localfunctions());
end
function testTranspose(tc)
syms z zeta
qSymbolic = quantity.Symbolic(...
[1+z*zeta, -zeta; -z, z^2], 'grid', {linspace(0, 1, 21), linspace(0, 1, 41)},...
'variable', {z, zeta}, 'name', 'q');
qSymbolicTransp = qSymbolic.';
tc.verifyEqual(qSymbolic(1,1).on(), qSymbolicTransp(1,1).on());
tc.verifyEqual(qSymbolic(2,2).on(), qSymbolicTransp(2,2).on());
tc.verifyEqual(qSymbolic(1,2).on(), qSymbolicTransp(2,1).on());
tc.verifyEqual(qSymbolic(2,1).on(), qSymbolicTransp(1,2).on());
end % testTranspose
% function testCtranspose(tc)
% syms z zeta
% qSymbolic = quantity.Symbolic(...
% [1+z*zeta, -zeta; -z, z^2], 'grid', {linspace(0, 1, 21), linspace(0, 1, 41)},...
% 'variable', {z, zeta}, 'name', 'q');
% qSymbolicCtransp = qSymbolic';
% tc.verifyEqual(qSymbolic(1,1).on(), qSymbolicCtransp(1,1).on());
% tc.verifyEqual(qSymbolic(2,2).on(), qSymbolicCtransp(2,2).on());
% tc.verifyEqual(qSymbolic(1,2).on(), qSymbolicCtransp(2,1).on());
% tc.verifyEqual(qSymbolic(2,1).on(), qSymbolicCtransp(1,2).on());
%
% qSymbolic2 = quantity.Symbolic(sym('z') * 2i + sym('zeta'), ...
% 'grid', {linspace(0, 1, 21), linspace(0, 1, 11)}, 'variable', sym({'z', 'zeta'}), 'name', 'im');
% qSymolic2Ctransp = qSymbolic2';
% tc.verifyEqual(qSymbolic2.real.on(), qSymolic2Ctransp.real.on());
% tc.verifyEqual(qSymbolic2.imag.on(), -qSymolic2Ctransp.imag.on());
% end % testTranspose
function testFlipGrid(tc)
syms z zeta
......
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