-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvergence_tests.m
More file actions
61 lines (60 loc) · 1.83 KB
/
convergence_tests.m
File metadata and controls
61 lines (60 loc) · 1.83 KB
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
56
57
58
59
60
61
%% Test convergence for sincfun class
clc, clf, format long
func='x.^0.5';
interval=[0,1];
f = eval(['@(x)',func]);
a=interval(1); b=interval(2);
Trials=[1:30]; Nvals=[Trials-1].^2;
errors=zeros(length(Nvals),1);
xx=linspace(interval(1),interval(2),202)';
% xx=rand(200,1);
tic
for k=Trials
m=k^2+1;
ff=sincfun(f,m,interval);
errors(k-Trials(1)+1)=max(abs(f(xx)-ff(xx)));
display(['sqrt(m) = ' num2str(k) ...
', error = ' num2str(errors(k-Trials(1)+1))])
end
toc
% convergence plot
LW = 'LineWidth'; MS = 'MarkerSize';
semilogy(sqrt(Nvals),errors,'b*',MS,10), hold on
semilogy(linspace(sqrt(Nvals(1)),sqrt(Nvals(end)),1000),ff.scl*sincfunpref('tol'),'-r'), hold off
xlabel('sqrt(N)'), ylabel('|| error ||_{\infty}','Rotation',0)
ylim([1e-16 1e1]),
xlim([Trials(1)-1 Trials(end)-1]), grid on
displayfunc=strrep(func,'.^','^{');
displayfunc=[displayfunc '}'];
title(['convergence for f(x) = ' displayfunc ' on (0,1) '])
shg
%% Test convergence for sincfun class
clc, clf, format long
func='x.^0.5';
interval=[0,1];
f = eval(['@(x)',func]);
a=interval(1); b=interval(2);
Trials=[1:30]; Nvals=[Trials-1].^2;
errors=zeros(length(Nvals),1);
xx=linspace(interval(1),interval(2),22)';
% xx=rand(200,1);
tic
for k=Trials
m=k^2+1;
ff=sincfun(f,m,interval);
errors(k-Trials(1)+1)=max(abs(f(xx)-ff(xx)));
display(['sqrt(m) = ' num2str(k) ...
', error = ' num2str(errors(k-Trials(1)+1))])
end
toc
% convergence plot
LW = 'LineWidth'; MS = 'MarkerSize';
semilogy(Nvals,errors,'b*',MS,10), hold on
semilogy(linspace(Nvals(1),Nvals(end),1000),ff.scl*sincfunpref('tol'),'-r'), hold off
xlabel('N'), ylabel('|| error ||_{\infty}','Rotation',0)
ylim([1e-16 1e1]),
xlim([Nvals(1) Nvals(end)]), grid on
displayfunc=strrep(func,'.^','^{');
displayfunc=[displayfunc '}'];
title(['convergence for f(x) = ' displayfunc ' on (0,1) '])
shg