Commit f45077d8 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete: removed size input parameter

parent 8e876f1d
......@@ -3,7 +3,7 @@ function [X, W] = solveGenericBvpFirstOrder(S, L, Az, A, A0, Q0, B, Cx, F, varar
% with 1st order derivatives.
%
% [X, W] = misc.solveGenericBvpFirstOrder(S, L, A, A0, C0, B, Cx, F, ...
% 'Cw', Cw, 'C', C, 'D', D, 'E', E)
% "Cw", Cw, "C", C, "D", D, "E", E)
% returns the solution of the BVP
% L(z) X(z)' + Az(z) X(z) + A0(z) E1.' X(0) - X(z) S = A(z)
% (E2.' - Q0 E1.') X(0) = B
......@@ -21,26 +21,26 @@ function [X, W] = solveGenericBvpFirstOrder(S, L, Az, A, A0, Q0, B, Cx, F, varar
% input checks
myParser = misc.Parser();
myParser.addRequired('S', @(v) isnumeric(v) && ismatrix(v));
myParser.addRequired('L', @(v) (isnumeric(v) && ismatrix(v)) || isa(v, 'quantity.Discrete'));
myParser.addRequired('Az', @(v) (isnumeric(v) && ismatrix(v)) || isa(v, 'quantity.Discrete'));
myParser.addRequired('A', @(v) (isnumeric(v) && ismatrix(v)) || isa(v, 'quantity.Discrete'));
myParser.addRequired('A0', @(v) (isnumeric(v) && ismatrix(v)) || isa(v, 'quantity.Discrete'));
myParser.addRequired('Q0', @(v) isnumeric(v) && ismatrix(v));
myParser.addRequired('B', @(v) isnumeric(v) && ismatrix(v));
myParser.addRequired('Cx', @(v) isa(v, 'model.Output'));
myParser.addRequired('F', @(v) isnumeric(v) && ismatrix(v));
myParser.addParameter('Cw', [], @(v) isnumeric(v) && ismatrix(v));
myParser.addParameter('C', [], @(v) isnumeric(v) && ismatrix(v));
myParser.addParameter('D', [], @(v) isnumeric(v) && ismatrix(v));
myParser.addParameter('E', [], @(v) isnumeric(v) && ismatrix(v));
myParser.addRequired("S", @(v) isnumeric(v) && ismatrix(v));
myParser.addRequired("L", @(v) (isnumeric(v) && ismatrix(v)) || isa(v, "quantity.Discrete"));
myParser.addRequired("Az", @(v) (isnumeric(v) && ismatrix(v)) || isa(v, "quantity.Discrete"));
myParser.addRequired("A", @(v) (isnumeric(v) && ismatrix(v)) || isa(v, "quantity.Discrete"));
myParser.addRequired("A0", @(v) (isnumeric(v) && ismatrix(v)) || isa(v, "quantity.Discrete"));
myParser.addRequired("Q0", @(v) isnumeric(v) && ismatrix(v));
myParser.addRequired("B", @(v) isnumeric(v) && ismatrix(v));
myParser.addRequired("Cx", @(v) isa(v, "model.Output"));
myParser.addRequired("F", @(v) isnumeric(v) && ismatrix(v));
myParser.addParameter("Cw", [], @(v) isnumeric(v) && ismatrix(v));
myParser.addParameter("C", [], @(v) isnumeric(v) && ismatrix(v));
myParser.addParameter("D", [], @(v) isnumeric(v) && ismatrix(v));
myParser.addParameter("E", [], @(v) isnumeric(v) && ismatrix(v));
myParser.parse2ws(S, L, Az, A, A0, Q0, B, Cx, F, varargin{:});
% Check if W has to be calculated or not
if any(strcmp(myParser.UsingDefaults, 'Cw')) ...
|| any(strcmp(myParser.UsingDefaults, 'C')) ...
|| any(strcmp(myParser.UsingDefaults, 'D')) ...
|| any(strcmp(myParser.UsingDefaults, 'W'))
if any(strcmp(myParser.UsingDefaults, "Cw")) ...
|| any(strcmp(myParser.UsingDefaults, "C")) ...
|| any(strcmp(myParser.UsingDefaults, "D")) ...
|| any(strcmp(myParser.UsingDefaults, "W"))
calculateW = false;
else
calculateW = true;
......
......@@ -82,7 +82,7 @@ end
PHI = quantity.Discrete({(element.upper - element.grid) / element.upper; ...
(element.grid / element.upper) }, ...
element, 'size', [2, 1], 'name', 'phi');
element, "name", "phi");
%% compute the mass matrix
M0 = 1 / 6 * [2, 1; 1, 2];
......
......@@ -77,8 +77,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
%% input parser
myParser = misc.Parser();
myParser.addParameter('name', "", @mustBe.gridName); % #fixme: shouldn't it be a text?
myParser.addParameter('figureID', 1, @isnumeric);
myParser.addParameter("name", "", @mustBe.gridName); % #fixme: shouldn't it be a text?
myParser.addParameter("figureID", 1, @isnumeric);
myParser.parse(varargin{:});
%% get the sizes of obj and grid
......@@ -95,24 +95,24 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% the initialization of quantity.Function and
% quantity.Symbolic objects
assert(isempty(myDomain) ... % constant case
|| all( cellfun(@isempty, valueOriginal ), 'all' ) ... % empty case
|| all( cellfun(@isempty, valueOriginal ), "all" ) ... % empty case
|| isequal([myDomain.n], size(valueOriginal{1}, 1 : max(1, numel(myDomain)))) ... % usual case
|| (isrow(valueOriginal{1}) && ... % row-vector case (including next line)
isequal([1, myDomain.n], size(valueOriginal{1}, 1 : max(1, numel(myDomain)+1)))), ...
'grids do not fit to valueOriginal');
"grids do not fit to valueOriginal");
% allow initialization of empty objects
valueOriginalSize = size(valueOriginal);
if any(valueOriginalSize == 0)
% If the size is specified in the arguements, it should
% be chosen instead of the default size from the
% valueOriginal.
myParser = misc.Parser();
myParser.addParameter('size', valueOriginalSize((1+ndims(myDomain)):end));
myParser.parse(varargin{:});
obj = quantity.Discrete.empty(myParser.Results.size);
return;
end
% % allow initialization of empty objects
% valueOriginalSize = size(valueOriginal);
% if any(valueOriginalSize == 0)
% % If the size is specified in the arguements, it should
% % be chosen instead of the default size from the
% % valueOriginal.
% myParser = misc.Parser();
% myParser.addParameter('size', valueOriginalSize((1+ndims(myDomain)):end));
% myParser.parse(varargin{:});
% obj = quantity.Discrete.empty(myParser.Results.size);
% return;
% end
% set valueDiscrete
for k = 1:numel(valueOriginal)
......@@ -393,8 +393,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% *) build a new valueDiscrete on the correct grid.
obj_hat = quantity.Discrete( newValues, tmpDomain.join, ...
'name', obj.name + "°" + g.name, ...
'size', size(obj));
'name', obj.name + "°" + g.name);
end % compose()
......@@ -1021,7 +1020,6 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
reshape(odeSolution, [myGridSize, size(obj)]), ...
[quantity.Domain(myParser.Results.newGridName, variableGrid), ...
quantity.Domain('ic', myParser.Results.initialValueGrid)], ...
'size', size(obj), ...
'name', "solve(" + obj(1).name + ")");
end % solveDVariableEqualQuantity()
......@@ -1563,14 +1561,12 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
elseif isa(obj, 'quantity.Symbolic')
f0 = misc.fundamentalMatrix.odeSolver_par(obj.function_handle, myGrid);
F = quantity.Discrete(f0, myDomain, ...
'size', [size(obj, 1), size(obj, 2)]);
F = quantity.Discrete(f0, myDomain);
else
f0 = misc.fundamentalMatrix.odeSolver_par( ...
obj.on(myGrid), ...
myGrid );
F = quantity.Discrete(f0, myDomain, ...
'size', [size(obj, 1), size(obj, 2)]);
F = quantity.Discrete(f0, myDomain);
end
end
......@@ -1622,7 +1618,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
yUnmuted(:,:,k) = sqrt(xPermuted(:,:,k));
end
y = quantity.Discrete(permute(yUnmuted, permuteBack), x(1).domain, ...
'size', size(x), 'name', "sqrtm(" + x(1).name + ")");
"name", "sqrtm(" + x(1).name + ")");
else
error('sqrtm() is only implemented for quadratic matrices');
end
......@@ -1699,18 +1695,17 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
return
end
if isa(b, 'double')
if isa(b, "double")
if numel(b) == 1
% simple multiplication in scalar case
P = quantity.Discrete(a.on() * b, a(1).domain, ...
'size', size(a), 'name', a(1).name + num2str(b));
P = quantity.Discrete(a.on() * b, a(1).domain, "name", a(1).name + num2str(b));
return
else
b = quantity.Discrete(b, quantity.Domain.empty(), 'size', size(b));
b = quantity.Discrete(b, quantity.Domain.empty());
end
end
if isa(a, 'double')
if isa(a, "double")
P = (b.' * a.').';
% this recursion is safe, because isa(b, 'double') is considered in
% the if above.
......@@ -2069,7 +2064,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
yUnmuted(:,:,k) = expm(xPermuted(:,:,k));
end
y = quantity.Discrete(permute(yUnmuted, permuteBack), x(1).domain, ...
'size', size(x), 'name', "expm(" + x(1).name + ")");
"name", "expm(" + x(1).name + ")");
end
end
......@@ -2089,8 +2084,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
function x = rdivide(A, B)
if isnumeric(A)
x = quantity.Discrete( A ./ B.on(), B(1).domain, ...
'size', size(B), 'name', "1 ./ " + B(1).name);
x = quantity.Discrete( A ./ B.on(), B(1).domain, "name", "1 ./ " + B(1).name);
else
error('Not yet implemented')
end
......@@ -2200,7 +2194,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
if obj.isNumber() && isempty(obj(1).gridName)
result = quantity.Discrete(zeros(size(obj)), obj(1).domain, ...
'size', size(obj), 'name', "(d_{.}" + obj(1).name + ")");
"name", "(d_{.}" + obj(1).name + ")");
return
end
......@@ -2443,7 +2437,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
absQuantity = quantity.Discrete.empty(size(obj));
else
absQuantity = quantity.Discrete(abs(obj.on()), obj(1).domain, ...
'size', size(obj), 'name', "|" + obj(1).name + "|");
"name", "|" + obj(1).name + "|");
end
end % abs()
......@@ -2488,14 +2482,13 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
function y = real(obj)
% real() returns the real part of the obj.
y = quantity.Discrete(real(obj.on()), obj(1).domain, ...
'name', "real(" + obj(1).name + ")", ...
'size', size(obj));
'name', "real(" + obj(1).name + ")");
end % real()
function y = imag(obj)
% real() returns the imaginary part of the obj.
y = quantity.Discrete(imag(obj.on()), obj(1).domain, ...
'name', "imag(" + obj(1).name + ")", 'size', size(obj));
'name', "imag(" + obj(1).name + ")");
end % imag()
function meanValue = mean(obj, dim)
......@@ -2613,7 +2606,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
P = quantity.Discrete.empty(valueSize);
else
O = ones([domain.gridLength, valueSize(:)']);
P = quantity.Discrete(O, domain, 'size', valueSize, varargin{:});
P = quantity.Discrete(O, domain, varargin{:});
end
end % ones()
......@@ -2661,7 +2654,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
P = quantity.Discrete.empty(valueSize);
else
O = zeros([domain.gridLength, valueSize(:)']);
P = quantity.Discrete(O, domain, 'size', valueSize, varargin{:});
P = quantity.Discrete(O, domain, varargin{:});
end
end % zeros()
......@@ -2859,7 +2852,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
1, (gridIndex+1):ndims(derivativeDiscrete)];
result = quantity.Discrete(...
permute(derivativeDiscrete, rePermutationVector), obj(1).domain, ...
'size', size(obj), 'name', "(d_{" + diffGridName + "}" + obj(1).name + ")");
"name", "(d_{" + diffGridName + "}" + obj(1).name + ")");
if k > 1
% if a higher order derivative is requested, call the function
......
......@@ -66,8 +66,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Piecewise < quantity.Discrete
joinedDomain = quantity.Domain(domainToJoin.name, joinedGrid);
initArgs = {joinedValues, joinedDomain, 'size', size(quantities{1}), ...
'name', optionalArgs.name};
initArgs = {joinedValues, joinedDomain, "name", optionalArgs.name};
end
obj@quantity.Discrete(initArgs{:});
......
......@@ -128,8 +128,8 @@ classdef SignalModel
result.v( t >= obj(i).occurrence, : ) = sol.v;
end
r = [r; quantity.Discrete(result.r, optArg.time, 'size', [obj(i).n_p, 1])];
v = [v; quantity.Discrete(result.v, optArg.time, 'size', [obj(i).n_v, 1])];
r = [r; quantity.Discrete(result.r, optArg.time)];
v = [v; quantity.Discrete(result.v, optArg.time)];
end
......
......@@ -261,14 +261,6 @@ Pt = quantity.Domain('p', t);
a = [Z, T, S];
b = [Ps, St];
c = Pt;
%
%
% a = quantity.Discrete(cat(4, sin(Z.*Z.*S), cos(Z.*T.*S)), ...
% 'size', [2 1], 'grid', {z, t, s}, 'gridName', {'z', 't', 's'});
% b = quantity.Discrete(ones(numel(s), numel(t)), ...
% 'size', [1 1], 'grid', {s, t}, 'gridName', {'p', 's'});
% c = quantity.Discrete(ones(numel(t), 2, 2), ...
% 'size', [2 2], 'grid', {t}, 'gridName', {'p'});
joinedDomainAB = sort( join(a, b) );
joinedDomainCC = sort( join(c, c) );
......
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