Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_construct_cov.m

raw
1 function covM = fn_construct_cov(diagcovM, corM)
2 % function corM = corr(covM)
3 % diagcovM: diag of covariance matrix (input)
4 % corM: correlation matrix (input)
5 % covM: covariance matrix (output)
6 % 9 May 2008
7 %
8 % Copyright (C) 1997-2012 Tao Zha
9 %
10 % This free software: you can redistribute it and/or modify
11 % it under the terms of the GNU General Public License as published by
12 % the Free Software Foundation, either version 3 of the License, or
13 % (at your option) any later version.
14 %
15 % It is distributed in the hope that it will be useful,
16 % but WITHOUT ANY WARRANTY; without even the implied warranty of
17 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 % GNU General Public License for more details.
19 %
20 % If you did not received a copy of the GNU General Public License
21 % with this software, see <http://www.gnu.org/licenses/>.
22 %
23
24
25 [nvar,jnk]=size(corM);
26 if nvar~=jnk
27 error('The input matrix must be square!!')
28 end
29 covM=zeros(nvar);
30
31 for i=1:nvar
32 for j=1:nvar
33 covM(i,j)= corM(i,j) * sqrt( diagcovM(i) * diagcovM(j) );
34 end
35 end
36