%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example file for generating an isotropic Smolyak grid based on the paper
%
% Nobile, F., Tempone, R., Webster, C.G. 
% A sparse grid stochastic collocation method for partial differential 
% equations with random input data. 
% SIAM J. Numer. Anal. 46(5), 2309–2345 (2008)
% Chapters 2.2-2.3
%
% edited by Anwar Khaddaj, School of Mathematical and Statistical Sciences,
% Arizona State University
% March 24, 2026

addpath('D:\ASU_research\EIT_ASU_Github\matlab\Xiu_paper_codes\chebfun');

%From Xiu's 2007 paper, J = N+k = 2+5=7; so qi=2^{i-1}+1. i here is 7
nx = 2^6+1;
ny = 2^6+1;
x = chebpts(nx); % uses chebfun software package
y = chebpts(ny);

[X, Y] = meshgrid(x, y);

figure;
plot(X(:), Y(:), 'r.', 'MarkerSize', 6);
axis equal;
xlim([-1 1]); ylim([-1 1]);
box on;

nDim = 2; % number of dimensions
nLev = 5; % level of the Smolyak grid
grid_type = 1; % specifies the type of grid 
               % 1: Clenshaw-Curtis quadrature
               % 2: Gaussian quadrature
smolyak_pts = generate_Smolyak_grid(nDim,nLev,grid_type);

%if we require a grid [a1,b1] x ... [an,bn], we may use the following:
% 
% grid_bounds = [-0.5 0.5; -0.5 0.5]; %bounds of the grid
% transformed_grid = transform_grid(smolyak_pts,grid_bounds);