


ensure proper mean and covariance THIS IS NO USER FUNCTION


0001 function [mean, cov] = ensureMeanAndCov(nDim, mean, cov) 0002 % ensure proper mean and covariance 0003 % 0004 % THIS IS NO USER FUNCTION 0005 0006 % The elk-library: convex geometry applied to crystallization modeling. 0007 % Copyright (C) 2013 Alexander Reinhold 0008 % 0009 % This program is free software: you can redistribute it and/or modify it 0010 % under the terms of the GNU General Public License as published by the 0011 % Free Software Foundation, either version 3 of the License, or (at your 0012 % option) any later version. 0013 % 0014 % This program is distributed in the hope that it will be useful, but 0015 % WITHOUT ANY WARRANTY; without even the implied warranty of 0016 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 % General Public License for more details. 0018 % 0019 % You should have received a copy of the GNU General Public License along 0020 % with this program. If not, see <http://www.gnu.org/licenses/>. 0021 0022 %% mean 0023 mean = mean(:); 0024 if ~isempty(nDim) && numel(mean) ~= nDim 0025 error('elk:distribution:wrongInput', ... 0026 'Mean vector has improper dimension'); 0027 else 0028 nDim = numel(mean); 0029 end 0030 0031 %% cov 0032 if (size(cov, 1) == nDim) && (size(cov, 2) == nDim) 0033 % everything OK 0034 elseif numel(cov) == 1 0035 cov = cov*eye(nDim); 0036 elseif numel(cov) == nDim 0037 % this case assumes that the std is provided 0038 cov = diag(cov); 0039 else 0040 error('elk:distribution:wrongInput', ['Covariance matrix does not ' ... 0041 'match the dimension of the continuous distribution']); 0042 end