-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #42 Enhancement: function plus added
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |