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

new: quantity.Discrete.iszero()

parent f515eec3
......@@ -58,5 +58,4 @@ else
output(it, :) = mySs.C * state(it, :).' + mySs.D * u(it, :).';
end % for it = 1 : numel(t)
end % if strcmp(solver, "lsim")
end % simulate()
end % simulate()
\ No newline at end of file
......@@ -1891,6 +1891,25 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
end % isnan()
function result = iszero(obj, allZero)
% iszero True for obj == 0.
% isnan(X) returns an array that contains true's where
% the elements of X == 0 and false's where they are not.
%
% iszero(X, true) returns the same as all(iszero(X), 'all')
arguments
obj
allZero = false;
end
if allZero
result = all(obj.on() == 0, 'all');
else
result = reshape(all(obj.on() == 0, 1:1:obj(1).nargin), size(obj));
end
end % iszero()
function P = ztzTimes(a, b)
assert(size(a,2) == size(b,1))
......
......@@ -12,6 +12,20 @@ testCase.TestData.sym.t = t;
testCase.TestData.sym.sy = sy;
end
function testIszero(tc)
z = quantity.Domain("z", linspace(0, 1, 11));
zeta = quantity.Domain("zeta", linspace(0, 1, 11));
zDiscrete = quantity.Discrete(z.grid, 'domain', z);
zetaDiscrete = quantity.Discrete(0*zeta.grid, 'domain', zeta);
result = logical([1, 0; 1, 0]);
nonZeroQuan = (result-1) * (zDiscrete + zetaDiscrete);
zeroQuan = (result-1) * (zDiscrete * zetaDiscrete);
tc.verifyEqual(nonZeroQuan.iszero(), result);
tc.verifyEqual(nonZeroQuan.iszero(true), false);
tc.verifyEqual(zeroQuan.iszero(), true(size(zeroQuan)));
tc.verifyEqual(zeroQuan.iszero(true), true);
end % testIszero()
function testDet(tc)
z = quantity.Domain("z", linspace(0, 1, 11));
zDiscrete = quantity.Discrete(z.grid, 'domain', z);
......
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