Skip to content

Commit

Permalink
Issue #42 Enhancement: function plus added
Browse files Browse the repository at this point in the history
  • Loading branch information
alextim27 committed Dec 5, 2015
1 parent 8a73abe commit a766674
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions products/+elltool/+core/@GenEllipsoid/GenEllipsoid.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function checkIsMe(objArr)
end
end
methods
outEllArr = plus(varargin)
function isOk=getIsGoodDir(ellObj1,ellObj2,curDirVec)
% Example:
% firstEllObj = elltool.core.GenEllipsoid([10;0], 2*eye(2));
Expand Down
99 changes: 99 additions & 0 deletions products/+elltool/+core/@GenEllipsoid/plus.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
function outEllArr = plus(varargin)
%
% PLUS - overloaded operator '+'
%
% outEllArr = PLUS(inpEllArr, inpVec) implements E(q, Q) + b
% for each GenEllipsoid E in inpEllArr.
% outEllArr = PLUS(inpVec, inpEllArr) implements b + E(q, Q)
% for each GenEllipsoid E in inpEllArr.
%
% Operation E + b (or b + E) where E = inpEll is an GenEllipsoid in R^n,
% and b = inpVec - vector in R^n. If E(q) is an GenEllipsoid
% with center q, then
% E(q) + b = b + E(q) = E(q + b).
%
% Input:
% regular:
% ellArr: GenEllipsoid [nDims1,nDims2,...,nDimsN] - array of
% GenEllipsoids of the same dimentions nDims.
% bVec: double[nDims, 1] - vector.
%
% Output:
% outEllArr: GenEllipsoid [nDims1,nDims2,...,nDimsN] - array of
% GenEllipsoids with same shapes as ellArr, but with centers shifted
% by vectors in bVec.
%
% Example:
% ellObj1 = elltool.core.GenEllipsoid([5;2], eye(2), [1 3; 4 5]);
% ellObj2 = elltool.core.GenEllipsoid([-1;-1], [5 3; 3 10]);
% ellVec = [ellObj1, ellObj2];
% outEllVec = ellVec + [1; 1]
%
% outEllVec =
%
% Structure(1, 1)
% |
% |----- q : [6 3]
% | -------
% |----- Q : |10|19|
% | |19|41|
% | -------
% | -----
% |-- QInf : |0|0|
% | |0|0|
% | -----
% O
%
% Structure(2, 1)
% |
% |----- q : [0 0]
% | -------
% |----- Q : |5 |3 |
% | |3 |10|
% | -------
% | -----
% |-- QInf : |0|0|
% | |0|0|
% | -----
% O
%
% $Author: Alexandr Timchenko <[email protected]> $
% $Date: Dec-2015$
% $Copyright: Moscow State University,
% Faculty of Computational Mathematics and Computer Science,
% System Analysis Department 2015 $
%

import modgen.common.throwerror;
import modgen.common.checkvar;
import modgen.common.checkmultvar;
import elltool.core.GenEllipsoid;
errMsg =...
'this operation is only permitted between GenEllipsoid and vector in R^n.';
checkvar(nargin,'x==2','errorTag','wrongInput',...
'errorMessage',errMsg)
if isa(varargin{1}, 'GenEllipsoid')&&isa(varargin{2}, 'double')
inpEllArr = varargin{1};
inpVec = varargin{2};
elseif isa(varargin{2}, 'GenEllipsoid')&&isa(varargin{1}, 'double')
inpEllArr = varargin{2};
inpVec = varargin{1};
else
throwerror('wrongInput',errMsg);
end
sizeCVec = num2cell(size(inpEllArr));
if isempty(inpEllArr)
outEllArr = GenEllipsoid.empty(sizeCVec{:});
else
dimArr = dimension(inpEllArr);
checkmultvar('iscolumn(x1)&&all(x2(:)==length(x1))',2,inpVec,dimArr,...
'errorMessage','dimensions mismatch');
outEllArr(sizeCVec{:})=GenEllipsoid;
arrayfun(@(x) fSinglePlus(x),1:numel(inpEllArr));
end
function fSinglePlus(index)
outEllArr(index).centerVec = inpEllArr(index).centerVec + inpVec;
outEllArr(index).diagMat = inpEllArr(index).diagMat;
outEllArr(index).eigvMat = inpEllArr(index).eigvMat;
end
end

0 comments on commit a766674

Please sign in to comment.