/ nodal-dg Public

## Commit

Browse the repository at this point in the history
starting code for computing Lebesgue constant
Tim Warburton authored and Tim Warburton committed Sep 7, 2016
1 parent e9a25c5 commit 50c09d1
Showing 3 changed files with 127 additions and 0 deletions.
58 changes: 58 additions & 0 deletions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
@@ -0,0 +1,58 @@

function maxleb = Lebesgue2D(N, r, s, Nsamples, Nlevels)

V = Vandermonde2D(N, r, s);

[Dr,Ds] = Dmatrices2D(N, r, s, V);
maxleb = norm(Dr);
return

lcoeffs = inv(V);

M = Nsamples;

% randomly sample lebesgue function
L1 = rand(M,1);
L2 = rand(M,1);
L3 = 1-L1-L2;
ids = find(L3>0);
L1 = L1(ids);
L2 = L2(ids);
L3 = L3(ids);

h = 1;

for cnt=1:Nlevels
f = derivlebfn2d(N, lcoeffs, L1, L2, L3);

[fsort, ids] = sort(-f);
ids = ids(1:(M/5));

L1 = L1(ids);
L2 = L2(ids);
L3 = L3(ids);

% now perturb again
h = h/2;
L1new = L1*ones(1, 20) + h*(2*rand(length(L1),20)-1);
L2new = L2*ones(1, 20) + h*(2*rand(length(L2),20)-1);
L3new = 1-L1new-L2new;

L1 = [L1(1:100);L1new(:)];
L2 = [L2(1:100);L2new(:)];
L3 = [L3(1:100);L3new(:)];

ids = find( (L1+L2+L3)<=1 & L1>=0 & L2>=0 & L3>=0);
L1 = L1(ids);
L2 = L2(ids);
L3 = L3(ids);

end

f = derivlebfn2d(N, lcoeffs, L1, L2, L3);

[fsort, ids] = sort(-f);
ids = ids(1);
maxleb = f(ids(1))

54 changes: 54 additions & 0 deletions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
@@ -0,0 +1,54 @@

function maxleb = Lebesgue2D(N, r, s, Nsamples, Nlevels)

V = Vandermonde2D(N, r, s);

lcoeffs = inv(V);

M = Nsamples;

% randomly sample lebesgue function
L1 = rand(M,1);
L2 = rand(M,1);
L3 = 1-L1-L2;
ids = find(L3>0);
L1 = L1(ids);
L2 = L2(ids);
L3 = L3(ids);

h = 1;

for cnt=1:Nlevels
f = lebfn2d(N, lcoeffs, L1, L2, L3);

[fsort, ids] = sort(-f);
ids = ids(1:(M/5));

L1 = L1(ids);
L2 = L2(ids);
L3 = L3(ids);

% now perturb again
h = h/2;
L1new = L1*ones(1, 20) + h*(2*rand(length(L1),20)-1);
L2new = L2*ones(1, 20) + h*(2*rand(length(L2),20)-1);
L3new = 1-L1new-L2new;

L1 = [L1(1:100);L1new(:)];
L2 = [L2(1:100);L2new(:)];
L3 = [L3(1:100);L3new(:)];

ids = find( (L1+L2+L3)<=1 & L1>=0 & L2>=0 & L3>=0);
L1 = L1(ids);
L2 = L2(ids);
L3 = L3(ids);

end

f = lebfn2d(N, lcoeffs, L1, L2, L3);

[fsort, ids] = sort(-f);
ids = ids(1);
maxleb = f(ids(1))

15 changes: 15 additions & 0 deletions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
@@ -0,0 +1,15 @@

function f = lebfn2d(N, lcoeffs, L1, L2, L3)

X = -1*L2 + 1*L3 + -1*L1;
Y = -1*L2 + -1*L3 + 1*L1;

vdm = Vandermonde2D(N, X, Y);

fn = vdm*lcoeffs;

f = sum(abs(fn'));