Added two routines for evaluating multivariate integrals with gaussian quadratures.
parent
8fa4bfc160
commit
f7b6e917ac
|
@ -0,0 +1,56 @@
|
||||||
|
function cprod = cartesian_product_of_sets(varargin)
|
||||||
|
% Computes the cartesian product.
|
||||||
|
|
||||||
|
%@info:
|
||||||
|
%! @deftypefn {Function File} {@var{cprod} =} cartesian_product_of_sets (@var{a},@var{b}, ...)
|
||||||
|
%! @anchor{cartesian_product_of_sets}
|
||||||
|
%! @sp 1
|
||||||
|
%! Computes A_1 * A_2 * .... * A_n with a generic set A_i = {e_1,e_2,e_3,...} where e_i is a string
|
||||||
|
%! or a number. It is assumed that each element e_i is unique in set A_i.
|
||||||
|
%! @sp 2
|
||||||
|
%! @strong{Inputs}
|
||||||
|
%! @sp 1
|
||||||
|
%! @table @ @var
|
||||||
|
%! @item a
|
||||||
|
%! n*1 vector of doubles.
|
||||||
|
%! @item a
|
||||||
|
%! m*1 vector of doubles.
|
||||||
|
%! @end table
|
||||||
|
%! @sp 1
|
||||||
|
%! @strong{Outputs}
|
||||||
|
%! @sp 1
|
||||||
|
%! @table @ @var
|
||||||
|
%! @item cprod
|
||||||
|
%! nm*2 matrix of doubles, the nodes cartesian product of sets @var{a} and @var{b}.
|
||||||
|
%! @end table
|
||||||
|
%! @sp 2
|
||||||
|
%! @strong{This function is called by:}
|
||||||
|
%! @sp 2
|
||||||
|
%! @strong{This function calls:}
|
||||||
|
%! @sp 2
|
||||||
|
%! @end deftypefn
|
||||||
|
%@eod:
|
||||||
|
|
||||||
|
% Copyright (C) 2011 Dynare Team
|
||||||
|
% stephane DOT adjemian AT univ DASH lemans DOT fr
|
||||||
|
%
|
||||||
|
% This file is part of Dynare.
|
||||||
|
%
|
||||||
|
% Dynare is free software: you can redistribute it and/or modify
|
||||||
|
% it under the terms of the GNU General Public License as published by
|
||||||
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
|
% (at your option) any later version.
|
||||||
|
%
|
||||||
|
% Dynare is distributed in the hope that it will be useful,
|
||||||
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
% GNU General Public License for more details.
|
||||||
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
[ F{1:nargin} ] = ndgrid( varargin{:} );
|
||||||
|
|
||||||
|
for i=1:nargin
|
||||||
|
cprod(:,i) = F{i}(:);
|
||||||
|
end
|
|
@ -0,0 +1,59 @@
|
||||||
|
function [nodes,weights] = gauss_hermite_weights_and_nodes(n)
|
||||||
|
% Computes the weights and nodes for an Hermite Gaussian quadrature rule.
|
||||||
|
|
||||||
|
%@info:
|
||||||
|
%! @deftypefn {Function File} {@var{nodes}, @var{weights} =} gauss_hermite_weights_and_nodes (@var{n})
|
||||||
|
%! @anchor{gauss_hermite_weights_and_nodes}
|
||||||
|
%! @sp 1
|
||||||
|
%! Computes the weights and nodes for an Hermite Gaussian quadrature rule. designed to approximate integrals
|
||||||
|
%! on the infinite interval (-\infty,\infty) of an unweighted smooth function.
|
||||||
|
%! @sp 2
|
||||||
|
%! @strong{Inputs}
|
||||||
|
%! @sp 1
|
||||||
|
%! @table @ @var
|
||||||
|
%! @item n
|
||||||
|
%! Positive integer scalar, number of nodes (order of approximation).
|
||||||
|
%! @end table
|
||||||
|
%! @sp 1
|
||||||
|
%! @strong{Outputs}
|
||||||
|
%! @sp 1
|
||||||
|
%! @table @ @var
|
||||||
|
%! @item nodes
|
||||||
|
%! n*1 vector of doubles, the nodes (roots of an order n Hermite polynomial)
|
||||||
|
%! @item weights
|
||||||
|
%! n*1 vector of doubles, the associated weights.
|
||||||
|
%! @end table
|
||||||
|
%! @sp 2
|
||||||
|
%! @strong{This function is called by:}
|
||||||
|
%! @sp 2
|
||||||
|
%! @strong{This function calls:}
|
||||||
|
%! @sp 2
|
||||||
|
%! @end deftypefn
|
||||||
|
%@eod:
|
||||||
|
|
||||||
|
% Copyright (C) 2011 Dynare Team
|
||||||
|
% stephane DOT adjemian AT univ DASH lemans DOT fr
|
||||||
|
%
|
||||||
|
% This file is part of Dynare.
|
||||||
|
%
|
||||||
|
% Dynare is free software: you can redistribute it and/or modify
|
||||||
|
% it under the terms of the GNU General Public License as published by
|
||||||
|
% the Free Software Foundation, either version 3 of the License, or
|
||||||
|
% (at your option) any later version.
|
||||||
|
%
|
||||||
|
% Dynare is distributed in the hope that it will be useful,
|
||||||
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
% GNU General Public License for more details.
|
||||||
|
%
|
||||||
|
% You should have received a copy of the GNU General Public License
|
||||||
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
b = sqrt([1:n-1]/2);
|
||||||
|
JacobiMatrix = diag(b,1)+diag(b,-1);
|
||||||
|
[JacobiEigenVectors,JacobiEigenValues] = eig(JacobiMatrix);
|
||||||
|
[nodes,idx] = sort(diag(JacobiEigenValues));
|
||||||
|
JacobiEigenVector = JacobiEigenVectors(1,:);
|
||||||
|
JacobiEigenVector = transpose(JacobiEigenVector(idx));
|
||||||
|
weights = JacobiEigenVector.^2;
|
||||||
|
nodes = sqrt(2)*nodes;
|
Loading…
Reference in New Issue