Commit 9031abd9 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Added point wise multiplication to quantity.Discrete

parent 975e7710
......@@ -1605,7 +1605,13 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
function P = mpower(a, p)
% a^p implemented by multiplication
assert(p==floor(p) && p > 0);
assert(p==floor(p), "The power must be an integer");
if p == 0
P = quantity.Discrete.ones(size(a), a(1).domain);
return
end
P = a;
for k = 1:(p-1)
P = P * a;
......@@ -1615,6 +1621,18 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
s = obj.name;
end % num2str()
function P = times(a, b)
assert( all( size(a) == size(b), 'all' ), 'the terms a and b must have the same size');
for i = 1:numel(a)
P(i) = a(i) * b(i);
end
P = reshape(P, size(a));
end
function P = mtimes(a, b)
% TODO rewrite the selection of the special cases! the
% if-then-cosntruct is pretty ugly!
......
......@@ -12,6 +12,24 @@ testCase.TestData.sym.t = t;
testCase.TestData.sym.sy = sy;
end
function timesTest(testCase)
t = quantity.Domain.defaultDomain(13, "t");
a(1) = quantity.Discrete(t.grid, 'domain', t);
a(2) = quantity.Discrete(t.grid.^2, 'domain', t);
a(3) = quantity.Discrete(t.grid.^3, 'domain', t);
p = a .* a;
p_(1) = quantity.Discrete(t.grid.^2, 'domain', t);
p_(2) = quantity.Discrete(t.grid.^4, 'domain', t);
p_(3) = quantity.Discrete(t.grid.^6, 'domain', t);
testCase.verifyEqual( p.on(), p_.on(),'AbsTol', 1e-15)
end
function testFindZeros(testCase)
x = quantity.Domain('x', linspace(0,1));
......
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