-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMonomials_1.m
57 lines (47 loc) · 2.95 KB
/
Monomials_1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
% Monomials_1.m is a routine that constructs integration nodes and weights
% under N-dimensional monomial (non-product) integration rule with 2N nodes;
% see the Supplement to "Numerically Stable and Accurate Stochastic Simulation
% Approaches for Solving Dynamic Economic Models" by Kenneth L. Judd, Lilia
% Maliar and Serguei Maliar, (2011), Quantitative Economics 2/2, 173–210
% (henceforth, JMM, 2011).
%
% This version: July 14, 2011. First version: August 27, 2009.
% -------------------------------------------------------------------------
% Inputs: "N" is the number of random variables; N>=1;
% "vcv" is the variance-covariance matrix; N-by-N
% Outputs: "n_nodes" is the total number of integration nodes; 2*N;
% "epsi_nodes" are the integration nodes; n_nodes-by-N;
% "weight_nodes" are the integration weights; n_nodes-by-1
% -------------------------------------------------------------------------
% Copyright © 2011 by Lilia Maliar and Serguei Maliar. All rights reserved.
% The code may be used, modified and redistributed under the terms provided
% in the file "License_Agreement.txt".
% -------------------------------------------------------------------------
function [n_nodes,epsi_nodes,weight_nodes] = Monomials_1(N,vcv)
n_nodes = 2*N; % Total number of integration nodes
% 1. N-dimensional integration nodes for N uncorrelated random variables with
% zero mean and unit variance
% ---------------------------------------------------------------------------
z1 = zeros(n_nodes,N); % A supplementary matrix for integration nodes;
% n_nodes-by-N
for i = 1:N % In each node, random variable i takes value either
% 1 or -1, and all other variables take value 0
z1(2*(i-1)+1:2*i,i) = [1; -1];
end % For example, for N = 2, z1 = [1 0; -1 0; 0 1; 0 -1]
% z = z1*sqrt(N); % Integration nodes
% 2. N-dimensional integration nodes and weights for N correlated random
% variables with zero mean and variance-covaraince matrix vcv
% ----------------------------------------------------------------------
sqrt_vcv = chol(vcv); % Cholesky decomposition of the variance-covariance
% matrix
R = sqrt(N)*sqrt_vcv; % Variable R; see condition (B.7) in the Supplement
% to JMM (2011)
epsi_nodes = z1*R; % Integration nodes; see condition ((B.7) in the
% Supplement% to JMM (2011); n_nodes-by-N
% 3. Integration weights
%-----------------------
weight_nodes = ones(n_nodes,1)/n_nodes;
% Integration weights are equal for all integration
% nodes; n_nodes-by-1; the weights are the same for
% the cases of correlated and uncorrelated random
% variables