-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZWTensorGrid.m
More file actions
33 lines (32 loc) · 819 Bytes
/
ZWTensorGrid.m
File metadata and controls
33 lines (32 loc) · 819 Bytes
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
function [z,w] = ZWTensorGrid(z1, w1, ndim)
%
% The routine takes a one-dimensional vector and construct ndim-dimensional
% tensor grid.
%
% z = TensorGrid(z1, w1, ndim)
%
% z1 -- vector of length np, row or column vector. 1d grid.
% w1 -- 1d weights.
% ndim -- dimensionality
% z -- ndim-dimensional tensor grid of size (ntot, ndim),
% where ntot = np^ndim.
%
% by Dongbin Xiu, 5/12/2006.
%
np = length(z1);
if ndim == 1
z = zeros(np,ndim); w=zeros(np,1);
z(:) = z1(:); w(:)=w1(:);
elseif ndim == 2
z = [z1(1) z1(1)]; w=w1(1)*w1(1);
for i=1:np
for j=1:np
if ((i~=1) | (j~=1))
z = [z; [z1(i) z1(j)]];
w = [w; w1(i)*w1(j)];
end
end
end
else
[z,w] = ZWTensorGrid(z1,w1,ndim-1);
end