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

quantity: added unitary minus and plus (uminus and uplus): -quant = (-1)*quant

parent 69fe72d3
......@@ -1487,6 +1487,18 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete
[C.name] = deal([A(1).name, '-', B(1).name]);
end
function C = uplus(A)
% unitary plus: C = +A
C = copy(A);
end
function C = uminus(A)
% unitary plus: C = -A
C = (-1) * A;
[C.name] = deal(['-', A(1).name]);
end
function [P, supremum] = relativeErrorSupremum(A, B)
assert(numel(A) == numel(B), 'Not implemented')
......
......@@ -4,6 +4,23 @@ function [tests] = testDiscrete()
tests = functiontests(localfunctions);
end
function testUnitaryPluasAndMinus(testCase)
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);
qDoubleArray = qSymbolic.on();
testCase.verifyEqual(on(-qSymbolic), -qDoubleArray);
testCase.verifyEqual(on(-qDiscrete), -qDoubleArray);
testCase.verifyEqual(on(+qSymbolic), +qDoubleArray);
testCase.verifyEqual(on(+qDiscrete), +qDoubleArray);
testCase.verifyEqual(on(+qDiscrete), on(+qSymbolic));
testCase.verifyEqual(on(-qDiscrete), on(-qSymbolic));
end
function testConcatenate(testCase)
t = linspace(0, pi)';
......
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