-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.m
55 lines (47 loc) · 1.52 KB
/
example2.m
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%%%%%
%% Numerical experiment 2:
%% "Large" length-scale with varying number of nodes
%%%%
% Parameter alpha
a = 1/sqrt(2);
% Parameters for the experiment
Ns = [2:20];
ells = [1.5 2 3 4 5];
% Storage
W = cell(length(ells),length(Ns));
Wa = cell(length(ells),length(Ns));
wmins = zeros(length(ells),length(Ns));
wamins = zeros(length(ells),length(Ns));
for i = 1:length(ells);
l = ells(i);
% Kernel for this length-scale
k = @(x,y) exp(-(x-y)^2/(2*l^2));
kmean = @(x) (l^2 / (1+l^2))^(1/2) * exp( -norm(x)^2 /(2*(1+l^2)) );
for j = 1:length(Ns);
N = Ns(j);
% Construct the nodes and compute the weights
[X, wa] = kq_approx(l,a,N);
w = kqw_symm(X, k, kmean);
% Save
W{i,j} = w;
Wa{i,j} = wa;
wmins(i,j) = min(w);
wamins(i,j) = min(wa);
end
end
% Compute some errors
esq = zeros(length(ells),length(Ns)); % Norm of the weight-wise relative error
emax = zeros(length(ells),length(Ns)); % Maximal absolute relative error
eabs = zeros(length(ells),length(Ns)); % Norm of the absolute weight-wise error
for i = 1:length(ells)
for j = 1:length(Ns)
esq(i,j) = sqrt(sum(((W{i,j}-Wa{i,j}) ./ W{i,j}).^2));
eabs(i,j) = sqrt(sum((W{i,j}-Wa{i,j}).^2));
emax(i,j) = max(abs((W{i,j}-Wa{i,j}) ./ W{i,j}));
end
end
semilogy(Ns,esq,'LineWidth',1.5)
title('Norm of the relative weight error vector')
xlabel('N')
legendCell = cellstr(num2str(ells', 'l = %.1f'));
legend(legendCell)