Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LRT_infinite_dimensional_systems
conI
Commits
50afa926
Commit
50afa926
authored
Feb 03, 2020
by
Ferdinand Fischer
Browse files
First version of the quantity.domain object.
parent
532c63d3
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
+misc/Parser.m
View file @
50afa926
...
...
@@ -6,13 +6,15 @@ classdef Parser < inputParser
methods
function
obj
=
Parser
()
function
obj
=
Parser
(
varargin
)
obj
=
obj
@
inputParser
();
% set default properties
obj
.
KeepUnmatched
=
true
;
obj
.
CaseSensitive
=
true
;
obj
.
PartialMatching
=
false
;
end
% Parser()
function
i
=
isDefault
(
obj
,
name
)
...
...
+misc/ensureIsCell.m
0 → 100644
View file @
50afa926
function
value
=
ensureIsCell
(
value
)
%ENSUREISCELL ensures that the value is a cell.
% c = ensureIsCell(value) checks if value is a cell. If it is not a cell,
% it is converted as a cell.
if
~
iscell
(
value
)
value
=
{
value
};
end
end
+quantity/Discrete.m
View file @
50afa926
This diff is collapsed.
Click to expand it.
+quantity/Domain.m
0 → 100644
View file @
50afa926
classdef
Domain
%DOMAIN class to describes a range of values on which a function can be defined.
% todo:
% * EquidistantDomain
% * multi dimensional
properties
% The discrete points of the grid for the evaluation of a
% continuous quantity. For an example, the function f(x) should be
% considered on the domain x \in X = [0, 1]. Then, a grid can be
% generated by X_grid = linspace(0, 1).
grid
double
{
mustBeReal
};
% a speaking name for this domain; Should be unique, so that the
% domain can be identified by the name.
name
char
;
end
properties
(
Dependent
)
n
;
% number of discretization points
lower
;
% lower bound of the domain
upper
;
% upper bound of the domain
end
methods
function
obj
=
Domain
(
varargin
)
%DOMAIN initialize the domain
%
if
nargin
>=
1
parser
=
misc
.
Parser
();
parser
.
addParameter
(
'grid'
,
[],
@
isvector
);
parser
.
addParameter
(
'name'
,
''
,
@
ischar
);
parser
.
parse
(
varargin
{:});
% todo: assertions
% * ascending ?
obj
.
grid
=
parser
.
Results
.
grid
(:);
obj
.
name
=
parser
.
Results
.
name
;
else
obj
=
quantity
.
Domain
.
empty
();
end
end
function
n
=
get
.
n
(
obj
)
n
=
length
(
obj
.
grid
);
end
function
lower
=
get
.
lower
(
obj
)
lower
=
min
(
obj
.
grid
);
end
function
upper
=
get
.
upper
(
obj
)
upper
=
max
(
obj
.
grid
);
end
function
nd
=
ndims
(
obj
)
%NDIMS number of dimensions of the domain specified by the
%object-array.
nd
=
size
(
obj
(:),
1
);
end
function
n
=
numGridElements
(
obj
)
% NUMGRIDLEMENTS returns the number of the elements of the grid
n
=
prod
([
obj
.
n
]);
end
function
s
=
gridLength
(
obj
)
%GRIDLENGTH number of discretization points for each grid in the
%object-array.
s
=
[
obj
.
n
];
end
end
methods
(
Static
)
function
g
=
defaultGrid
(
gridSize
,
name
)
if
nargin
==
1
% If no names are specified, chose x_1, x_2, ... as default
% names.
name
=
cell
(
1
,
length
(
gridSize
));
for
k
=
1
:
length
(
gridSize
)
name
{
k
}
=
[
'x_'
num2str
(
k
)];
end
end
% generate a default gird with given sizes
g
=
quantity
.
Domain
.
empty
();
for
k
=
1
:
length
(
gridSize
)
o
=
ones
(
1
,
length
(
gridSize
)
+
1
);
% + 1 is required to deal with one dimensional grids
o
(
k
)
=
gridSize
(
k
);
O
=
ones
(
o
);
O
(:)
=
linspace
(
0
,
1
,
gridSize
(
k
));
g
(
k
)
=
quantity
.
Domain
(
'grid'
,
O
,
'name'
,
name
{
k
});
end
end
end
end
+quantity/EquidistantDomain.m
0 → 100644
View file @
50afa926
classdef
EquidistantDomain
<
quantity
.
Domain
%EQUIDISTANTDOMAIN class to handle the discretization of the range of
%definition of a function. The discretization points are equally
%distributed over the domain.
properties
Property1
end
methods
function
obj
=
untitled
(
inputArg1
,
inputArg2
)
%UNTITLED Construct an instance of this class
% Detailed explanation goes here
obj
.
Property1
=
inputArg1
+
inputArg2
;
end
function
outputArg
=
method1
(
obj
,
inputArg
)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
outputArg
=
obj
.
Property1
+
inputArg
;
end
end
end
+unittests/+quantity/testDomain.m
0 → 100644
View file @
50afa926
function [tests] = testDomain()
tests = functiontests(localfunctions);
end
function setupOnce(testCase)
end
function testDomainInit(testCase)
Z = linspace(0,pi, 3);
d = quantity.Domain('name', 'z', 'grid', Z);
D = [d d];
testCase.verifyEqual( ndims(D), 2);
testCase.verifyEqual( ndims(d), 1);
end
function testDomainGridLength(testCase)
Z = linspace(0,pi, 3);
d = quantity.Domain('name', 'z', 'grid', Z);
D = [d d];
testCase.verifyEqual( cellfun(@(v) numel(v), {Z, Z}), D.gridLength)
end
function testDomainNumGridElements(testCase)
Z = linspace(0,pi, 3);
d = quantity.Domain('name', 'z', 'grid', Z);
D = [d d];
testCase.verifyEqual( D.numGridElements, prod([length(Z), length(Z)]));
end
function testDomainEmpty(testCase)
d = quantity.Domain();
testCase.verifyTrue( isempty(d) )
end
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment