Commit 6ef08d4d authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Point wise power of quantity.Discrete can now compute non integer powers

parent 8508afca
......@@ -1610,8 +1610,19 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% a.^p implemented by multiplication
% #todo unittest required
P = quantity.Discrete.zeros(size(obj), obj(1).domain);
for k = 1:numel(obj)
P(k) = obj(k)^p;
if round(p) == p
% power of integer order:
for k = 1:numel(obj)
P(k) = obj(k)^p;
end
else
% power of not integer order
for k = 1:numel(obj)
P(k) = obj(k).copy();
P(k).valueDiscrete = obj(k).valueDiscrete.^p;
P(k).name = obj(k).name + ".^" + num2str(p);
end
end
end
function P = mpower(a, p)
......
......@@ -12,6 +12,25 @@ testCase.TestData.sym.t = t;
testCase.TestData.sym.sy = sy;
end
function powerTest(testCase)
t = quantity.Domain("t", linspace(0,1));
p(1,1) = Discrete(t);
p(2,1) = Discrete(t)^2;
p2 = p.^2;
testCase.verifyEqual(p2(1).on(), t.grid.^2)
testCase.verifyEqual(p2(2).on(), t.grid.^4, 'AbsTol', 1e-15)
p25 = p.^2.5;
testCase.verifyEqual(p25(1).on(), t.grid.^2.5);
testCase.verifyEqual(p25(2).on(), t.grid.^5, 'AbsTol', 1e-15);
end
function timesTest(testCase)
t = quantity.Domain.defaultDomain(13, "t");
......
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