Skip to content

Commit

Permalink
[wip] some cleanup; mostly in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ezander committed Jun 10, 2013
1 parent 28d9d7c commit a3148c4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 31 deletions.
6 changes: 4 additions & 2 deletions gpc/gpc_sample.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
% is the number of random variables. V contains a specification of the
% random variables and a multiindex set (see Example).
%
% Example (<a href="matlab:run_example gpc_sample">run</a>)
% Example 1 (<a href="matlab:run_example gpc_sample 1">run</a>)
% I = multiindex(3,2);
% V = {'H', I};
% xi = gpc_sample(V, 5)
% V = {'PHp', I};
%
% Example 2 (<a href="matlab:run_example gpc_sample 2">run</a>)
% V = {'PLp', [0, 0, 0]};
% xi = gpc_sample(V, 3000);
% plot(xi(1,:), xi(2,:), '.')
% xlabel('Uniform'); ylabel('Gauss');
Expand Down
29 changes: 0 additions & 29 deletions testing/corput.m

This file was deleted.

File renamed without changes.
22 changes: 22 additions & 0 deletions testing/test_cc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function test_cc

[x,w]=clencurt(9)
sum(w)

function [x,w]=clencurt(n)
% Computes the Clenshaw Curtis nodes and weights
% Adapted a code by G. von Winckel
% http://www.scientificpython.net/1/post/2012/04/clenshaw-curtis-quadrature.html
if n == 1
x = 0;
w = 2;
else
C = zeros(n,2);
k = 2*(1:floor((n-1)/2));
C(1:2:end,1) = 2./[1, 1-k.*k];
C(2,2) = -(n-1);
V = [C; flipud(C(2:n-1,:))];
F = real(ifft(V)); %, n=None, axis=0))
x = F(1:n,2);
w = [F(1,1), 2*F(2:n-1,1)', F(n,1)];
end
52 changes: 52 additions & 0 deletions testing/test_fejer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function test_fejer


cc_fejer(5, 1)
cc_fejer(5, 2)
cc_fejer(5, 3)
sum(cc_fejer(5, 1))
sum(cc_fejer(5, 2))
sum(cc_fejer(5, 3))

[w1,w2,wc]=fejer(16);
wc(end+1)=wc(1);
sum(wc)
length(wc)


function w = cc_fejer(n, mode)
[wf1,wf2,wcc] = fejer(n);
switch mode
case 1
w = wf1';
case 2
w = wf2(2:end)';
case 3
w = [wcc; wcc(1)]';
otherwise
error('foo');
end




function [wf1,wf2,wcc] = fejer(n)
%BIT Numerical Mathematics
%March 2006, Volume 46, Issue 1, pp 195-202
%Fast Construction of the Fejér and Clenshaw–Curtis Quadrature Rules
% doi: 10.1007/s10543-006-0045-4



% Weights of the Fejer2, Clenshaw-Curtis and Fejer1 quadratures
% by DFTs. Nodes: x_k = cos(k*pi/n), n>1
N=[1:2:n-1]'; l=length(N); m=n-l; K=[0:m-1]';
% Fejer2 nodes: k=0,1,...,n; weights: wf2, wf2_n=wf2_0=0
v0=[2./N./(N-2); 1/N(end); zeros(m,1)];
v2=-v0(1:end-1)-v0(end:-1:2); wf2=ifft(v2);
%Clenshaw-Curtis nodes: k=0,1,...,n; weights: wcc, wcc_n=wcc_0
g0=-ones(n,1); g0(1+l)=g0(1+l)+n; g0(1+m)=g0(1+m)+n;
g=g0/(n^2-1+mod(n,2)); wcc=ifft(v2+g);
% Fejer1 nodes: k=1/2,3/2,...,n-1/2; vector of weights: wf1
v0=[2*exp(i*pi*K/n)./(1-4*K.^2); zeros(l+1,1)];
v1=v0(1:end-1)+conj(v0(end:-1:2)); wf1=ifft(v1);
File renamed without changes.

0 comments on commit a3148c4

Please sign in to comment.