From d4bdd4551a9393e67dc57d2f8e107a8e55fcda3d Mon Sep 17 00:00:00 2001 From: Ferdinand Fischer <ferdinand.fischer@fau.de> Date: Wed, 15 May 2019 12:13:37 +0200 Subject: [PATCH] Removed the concatanation functions form the quantity.Symbolic class. This functions seemed to be depricated. --- +quantity/Discrete.m | 4 +- +quantity/Symbolic.m | 58 +++++++++-------------------- +unittests/+quantity/testSymbolic.m | 34 ++++++++++++++++- 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/+quantity/Discrete.m b/+quantity/Discrete.m index a316e50..afc6b5a 100644 --- a/+quantity/Discrete.m +++ b/+quantity/Discrete.m @@ -27,8 +27,8 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete % ID of the figure handle in which the handle is plotted figureID double = 1; - % TODO@ff vermutlich ist es schöner einen converter auf dieses - % Objekt zu schreiben, als es hier als Eigenschaft dran zu hängen. + % TODO@ff vermutlich ist es schöner einen converter auf dieses + % Objekt zu schreiben, als es hier als Eigenschaft dran zu hängen. exportData export.Data; % Name of this object diff --git a/+quantity/Symbolic.m b/+quantity/Symbolic.m index 66d08ed..ff32827 100644 --- a/+quantity/Symbolic.m +++ b/+quantity/Symbolic.m @@ -97,21 +97,35 @@ classdef Symbolic < quantity.Function end end end - + function i = get.isConstant(obj) i = isempty(symvar(obj.valueSymbolic)); end function i = eq(A, B) + %== Equal. + % A == B does element by element comparisons between A and B and returns + % an array with elements set to logical 1 (TRUE) where the relation is + % true and elements set to logical 0 (FALSE) where it is not. A and B + % must have compatible sizes. In the simplest cases, they can be the same + % size or one can be a scalar. Two inputs have compatible sizes if, for + % every dimension, the dimension sizes of the inputs are either the same + % or one of them is 1. + % + % Two quantity.Symbolic objects are equal if they have the + % same symbolic expression, same gridSize and same + % variables. + i = all(size(A) == size(B)); if ~i return; end - for k = 1:numel(A) - i = i && isequal(A(k).valueSymbolic, B(k).valueSymbolic); - end + i = i && isequal([A.valueSymbolic], [B.valueSymbolic]); + i = i && isequal(A.grid, B.grid); + i = i && isequal(A.variable, B.variable); + end function operator = quantity.Operator(obj) @@ -382,43 +396,7 @@ classdef Symbolic < quantity.Function 'grid', {myParser.Results.variableGrid, myParser.Results.initialValueGrid}, ... 'name', ['solve(', obj(1).name, ')']); end - - function c = vertcat(a, varargin) - - if ~isa(a, 'quantity.Symbolic') - for k = 1:numel(varargin) - if isa(varargin{k}, 'quantity.Symbolic') - argin = getCopyParameters(varargin{k}); - a = quantity.Symbolic(a, argin{:}); - break; - end - end - end - - for k = 1:numel(varargin) - if ~isa(varargin{k}, 'quantity.Symbolic') - argin = getCopyParameters(a(1)); - varargin{k} = quantity.Symbolic(varargin{k}, argin{:}); - end - assert(~any( diff(cellfun(@(c) length(c), [a.grid, varargin{k}.grid])) ), 'Grids must have the same size'); - end - - c = vertcat@quantity.Discrete(a, varargin{:}); - %c = builtin('vertcat', a, varargin{:}); - end - - - - function c = horzcat(a, varargin) - - for k = 1:numel(varargin) - varargin{k} = varargin{k}.'; - end - - c = vertcat(a.', varargin{:}).'; - end - function sym = sym(obj) sym = reshape([obj.valueSymbolic], size(obj)); end diff --git a/+unittests/+quantity/testSymbolic.m b/+unittests/+quantity/testSymbolic.m index 467bab6..925e89e 100644 --- a/+unittests/+quantity/testSymbolic.m +++ b/+unittests/+quantity/testSymbolic.m @@ -4,6 +4,35 @@ function [tests ] = testSymbolic() tests = functiontests(localfunctions()); end +function testCat(testCase) +syms z zeta +f1 = quantity.Symbolic(1+z*z, 'grid', {linspace(0, 1, 21)}, 'variable', {z}, 'name', 'f1'); +f2 = quantity.Symbolic(sin(z), 'grid', {linspace(0, 1, 21)}, 'variable', {z}, 'name', 'f2'); + +% vertical concatanation +F = [f1; f2]; +testCase.verifyTrue(F(1) == f1) +testCase.verifyTrue(F(2) == f2) + +% horizontal concatanation +F = [f1, f2]; +testCase.verifyTrue(F(1) == f1) +testCase.verifyTrue(F(2) == f2) + +% combined concatanation +F = [F; f1, f2]; +testCase.verifyTrue(F(1,1) == f1); +testCase.verifyTrue(F(1,2) == f2); +testCase.verifyTrue(F(2,1) == f1); +testCase.verifyTrue(F(2,2) == f2); + +% concatanation on different grids +f3 = quantity.Symbolic(cos(z), 'grid', {linspace(0, 1, 13)}, 'variable', {z}, 'name', 'f1'); + +F = [f1, f3]; +testCase.verifyEqual(F(2).gridSize, f1.gridSize) + +end function testExp(testCase) % 1 spatial variable @@ -436,12 +465,15 @@ R1 = quantity.Symbolic([f1, f2; 0, f3], ... R2 = quantity.Symbolic([f2, f1; 0, f3], ... 'grid', {z}); +R3 = quantity.Symbolic([f1, f2; 0, f3], ... + 'grid', {z}); + %% verifyTrue(testCase, Q == P); verifyTrue(testCase, Q == Q); verifyTrue(testCase, R1 == R1); verifyFalse(testCase, R1 == R2); - +verifyTrue(testCase, R1 == R3); end function testEvaluateConstant(testCase) -- GitLab