%-----------------------------------------------------------
% This is a simple driver for plotting the hyperinterpolation
% relative errors on three parametrised test functions
%------------------------------------------------------------
%
% Authors: Stefano De Marchi and Marco Vianello
%          University of Padova
%
% October 2015
%------------------------------------------------------------
clear all
%close all

deg_max=input('max hyperinterpolation degree = ');  %max hyper degree

pts1d=linspace(-1,1,10); % equispaced points on [-1,1]

% set functions

% ----- power function
% b=3;
% f3=@(x,y,z) sqrt(x.^2+y.^2+z.^2).^b;

% ----- polynomial of degree 2k
% k=10;
% f3=@(x,y,z) (x.^2+y.^2+z.^2).^k;

% ---- gaussian
 c=1;
 f3=@(x,y,z) exp(-c*(x.^2+y.^2+z.^2));


for deg=1:deg_max

    [ptsx,ptsy,ptsz]=meshgrid(pts1d);
    pts=[ptsx(:) ptsy(:) ptsz(:)];

    [hyperval,cfs]=hyperlissa(deg,pts,f3);
    ff3=f3(pts(:,1), pts(:,2), pts(:,3));

    err(deg)=norm(hyperval-ff3)/norm(ff3);

end

semilogy(1:length(err),err,'-o');
xlabel('degree'); ylabel('rel. errors')

