Last change
on this file since 17 was
17,
checked in by zhangj, 10 years ago
|
To have a stable version on the server.
|
-
Property svn:executable set to
*
|
File size:
2.5 KB
|
Line | |
---|
1 | function pass = splittingtest |
---|
2 | % Test for exact jump detection and singular function approximation. |
---|
3 | % Rodrigo Platte. |
---|
4 | |
---|
5 | tol = chebfunpref('eps'); |
---|
6 | |
---|
7 | splitting on |
---|
8 | debug = false; |
---|
9 | Ntests = 3; |
---|
10 | |
---|
11 | pass = true; |
---|
12 | try |
---|
13 | for j = 1:Ntests |
---|
14 | |
---|
15 | % test jumps |
---|
16 | x0 = rand; |
---|
17 | f= chebfun(@(x) exp(x) +cos(7*x) + sign(x-x0)); |
---|
18 | pass = pass && f.ends(2) == x0 && (length(f.ends) < 4); |
---|
19 | if ~pass |
---|
20 | error('jump1') |
---|
21 | end |
---|
22 | |
---|
23 | x0 = rand; |
---|
24 | x0 = sign(x0-.5)*x0/100; % change sign and closer to origin |
---|
25 | f= chebfun(@(x) exp(x) +cos(7*x) + sign(x-x0)); |
---|
26 | pass = pass && f.ends(2) == x0 && (length(f.ends) < 4); |
---|
27 | if ~pass |
---|
28 | error('jump2') |
---|
29 | end |
---|
30 | |
---|
31 | if chebfunpref('eps') > 1/1000 |
---|
32 | x0 = rand; |
---|
33 | x0 = sign(x0-.5)*x0/1000; % change sign and even closer to origin |
---|
34 | f= chebfun(@(x) exp(x) +cos(7*x) + 0.1*sign(x-x0))+1; |
---|
35 | pass = pass && f.ends(2) == x0 && (length(f.ends) < 4); |
---|
36 | if ~pass |
---|
37 | error('jump3') |
---|
38 | end |
---|
39 | end |
---|
40 | |
---|
41 | % test C0 functions |
---|
42 | x0 = rand; |
---|
43 | x0 = sign(x0-.5)*x0; % change sign and closer to origin |
---|
44 | f= chebfun(@(x) exp(x) +cos(7*x) + abs(x-x0)); |
---|
45 | pass = pass && (length(f.ends)<3) || (abs(f.ends(2) - x0)< 1e-12*(tol/eps) && (length(f.ends) < 4)); |
---|
46 | if ~pass |
---|
47 | abs(f.ends(2) - x0) |
---|
48 | error('C0') |
---|
49 | end |
---|
50 | |
---|
51 | % test C1 functions |
---|
52 | x0 = rand; |
---|
53 | x0 = sign(x0-.5)*x0; |
---|
54 | f= chebfun(@(x) (x-x0).^2.*double(x>x0)); |
---|
55 | pass = pass && abs(f.ends(2) - x0)< 1e-8*(tol/eps) && (length(f.ends) < 4); |
---|
56 | if ~pass |
---|
57 | error('C1') |
---|
58 | end |
---|
59 | |
---|
60 | % test C2 functions |
---|
61 | x0 = rand; |
---|
62 | x0 = sign(x0-.5)*x0/100; % change sign and closer to origin |
---|
63 | f= chebfun(@(x) exp(x) + abs(x-x0).^3+1); |
---|
64 | pass = pass && abs(f.ends(2) - x0)< 1e-4*(tol/eps) && (length(f.ends) < 4); |
---|
65 | if ~pass |
---|
66 | error('C2') |
---|
67 | end |
---|
68 | |
---|
69 | % test C3 functions |
---|
70 | x0 = rand; |
---|
71 | x0 = sign(x0-.5)*x0/100; |
---|
72 | f= chebfun(@(x) (x-x0).^4.*double(x>x0)); |
---|
73 | pass = pass && (length(f.ends) < 5); |
---|
74 | if ~pass |
---|
75 | error('C3') |
---|
76 | end |
---|
77 | |
---|
78 | end |
---|
79 | |
---|
80 | % test sqrt |
---|
81 | ff = @(x) sqrt(x-2)+10; |
---|
82 | f = chebfun(ff, [2,20]); |
---|
83 | xx = linspace(2,10); |
---|
84 | pass = pass && length(f) <600 && norm(f(xx) - ff(xx),inf)<5e-7*(tol/eps); |
---|
85 | if ~pass |
---|
86 | error('SQRT') |
---|
87 | end |
---|
88 | |
---|
89 | |
---|
90 | catch |
---|
91 | |
---|
92 | if debug |
---|
93 | err=lasterror; |
---|
94 | disp('catch') |
---|
95 | disp(x0) |
---|
96 | disp(err.message) |
---|
97 | end |
---|
98 | |
---|
99 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.