-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchebfunpref.m
More file actions
236 lines (222 loc) · 8.33 KB
/
chebfunpref.m
File metadata and controls
236 lines (222 loc) · 8.33 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
function varargout = chebfunpref(varargin)
% CHEBFUNPREF Settings for Chebfun.
%
% CHEBFUNPREF, by itself, returns a structure with current preferences as
% fields/values. Use it to find out what preferences are available.
%
% CHEBFUNPREF(PREFNAME) returns the value corresponding to the preference
% named in the string PREFNAME.
%
% CHEBFUNPREF('factory') restore all preferences to their factory defined
% values.
%
% CHEBFUNPREF(PREFNAME,PREFVAL) sets the preference PREFNAME to the value
% PREFVAL. If PREFVAL is 'factory', PREFNAME is set to its factory defined
% value. S = CHEBFUNPREF(PREFNAME,PREFVAL) will store the current state of
% chebfunpref to S before changing PREFNAME.
%
% S = CHEBFUNPREF will return the current preferences in a structure, which
% may then be used in the form CHEBFUNPREF(P) to reload them or be passed
% to the Chebfun constructor.
%
% S = CHEBFUNPREF('factory') returns a structure S with the factory values
% without restoring them. V = CHEBFUNPREF(PREFNAME,'factory') returns the
% factory value V for preference PREFNAME without changing it.
%
% CHEBFUNPREF creates a persistent variable that stores these preferences.
% CLEAR ALL will not clear preferences, but MUNLOCK CHEBFUNPREF followed by
% CLEAR CHEBFUNPREF will (quitting Matlab also clears this variable).
%
% CHEBFUN PREFERENCES (case sensitive)
%
% splitting - Splitting option, true (1) or false (0).
% If true, breakpoints between funs may be introduced where a
% discontinuity in a function or a low-order derivative is detected,
% or if a global polynomial representation will be too long.
% If false, breakpoints will be introduced only at points where
% discontinuities are being created, e.g. by ABS(F) at points where
% a chebfun F passes through zero. Factory value is false.
%
% minsamples - Minimum number of points used by the constructor. The
% constructed fun or chebfun might be shorter as a result of the
% simplify command. Must be of the form 2^n+1. Factory value is 9.
%
% maxdegree - Maximum degree used by the constructor in SPLITTING OFF mode.
% Factory value is 2^16.
%
% maxlength - Maximum number of points used by the constructor in SPLITTING
% ON mode. Factory value is 6000.
%
% splitdegree - Maximum degree per fun used by the constructor in SPLITTING
% ON mode. Values should normally be of the form 2^n.
% Factory value is 128.
%
% resampling - Resample option, true (1) or false (0).
% If true, every function value is computed afresh as the constructor
% tries grids of size 9, 17, 33, etc. If false, old values are
% reused. (This sounds like an obvious speedup for most applications
% but in fact often does not result in an improvement.)
% Factory value is false.
%
% domain - Default interval of definition of a chebfun.
% Factory definition is [-1 1].
%
% eps - Relative tolerance used in construction and subsequent operations.
% Factory value is 2^-52 (Matlab's factory value of machine epsilon).
%
% sampletest - Safety test option, true (1) or false (0).
% If true, the constructor tests the function at one more arbitrary
% point to minimize the risk of missing signals between grid points.
% Factory value is true.
%
% blowup - Blowup option:
% BLOWUP=0: bounded functions only
% BLOWUP=1: poles are permitted (integer order)
% BLOWUP=2: blowup of integer or non-integer orders permitted (experimental)
% Factory value 0.
%
% chebkind - Interpolation points for the construction of chebfuns:
% CHEBKIND = 1: Chebyshev points of the first kind (experimental)
% CHEBKIND = 2: Chebyshev points of the secnod kind (recommended)
% Factory value is 2.
%
% extrapolate - Extrapolation at endpoints, true (1) or false (0).
% If true, function values at endpoints maybe extrapolated from
% interior values rather than sampled. Extrapolation is used
% independently of this option if a function evaluation returns NaN.
% In some cases, however, functions values at end points maybe
% inaccurate or undefined, and enabling extrapolation maybe helpful.
% Factory value is 0.
%
% plot_numpts - Number of points used to plot a chebfun.
% Factory value is 2001.
%
% Examples
% chebfunpref
% chebfunpref('minsamples', 17)
% chebfunpref('minsamples','factory')
% chebfunpref('factory')
%
% See also SPLITTING, RESAMPLING, BLOWUP
% Copyright 2011 by The University of Oxford and The Chebfun Developers.
% See http://www.maths.ox.ac.uk/chebfun/ for Chebfun information.
% persistent variables are known only to the function in which they are
% declared.
persistent prefs
% First call; set factory values
if isempty(prefs)
prefs = initPrefs();
if nargout == 1
varargout = {prefs};
end
mlock % Locks the currently running M-file so that clear functions do not remove it.
% Use munlock and clear chebfunpref if you edit this file.
end
% To speedup preference checks, try this first.
% -----------------------------------------------
if nargin == 1
try
varargout{1} = prefs.(lower(varargin{1}));
return
catch
% Move on to longer process.
end
end
% -----------------------------------------------
% If the above didn't work, go through the longer process:
% Assign putput prefs before changes are made.
if nargout == 1, varargout = {prefs}; end
if nargin == 1 % Restore defaults?
if isstruct(varargin{1})
% Assign prefs from structure input
prefs = varargin{1};
return
elseif strncmpi(varargin{1},'factory',3)
if nargout == 0
% Restore defaults
prefs = initPrefs();
else
% Return factory values without changing chebfunpref
varargout = {initPrefs()};
end
return
end
elseif nargin == 2 % Error catching
if ~isfield(prefs,varargin{1})
error('CHEBFUN:chebfunpref:argin', ...
['Unknown chebfun preference "',varargin{1},'".'])
end
elseif nargin > 2 % Allow setting of multiple values by recursive calls
while ~isempty(varargin) % Recurse
if numel(varargin) == 1
error('CHEBFUN:chebfunpref:argin2','Incorrect number of input arguments.');
end
chebfunpref(varargin{1:2});
varargin(1:2) = [];
end
if nargout == 1
varargout = {chebfunpref};
end
return
end
% Assign output values
if nargin == 0
varargout = { prefs };
elseif nargin == 1
varargout = { prefs.(varargin{1}) };
elseif nargin == 2
prop = lower(varargin{1}); val = varargin{2};
if ischar(val)
if strncmpi(val,'factory',3)
factoryvals = initPrefs;
val = factoryvals.(prop);
if nargout == 0
% Set preference to its factory value.
prefs.(prop) = val;
else
% Return factory value without changing chebfunpref variable
varargout = {val};
end
return
elseif strcmpi(val,'on')
val = true;
elseif strcmpi(val,'off')
val = false;
else
error('CHEBFUN:chebfunpref:argin','Invalid second argument.')
end
end
% If preference is 'eps', check for consistency!
if strcmp(prop,'eps') && val<2^-52
val = 2^-52;
warning('CHEBFUN:chebfunpref:argin',...
'eps value below machine precision. eps set to 2^-52.');
end
% Set preference!
prefs.(prop) = val;
if ~prefs.resampling && prefs.chebkind == 1
warning('CHEBFUN:resampling_kind',...
'RESAMPLING has been turned ON. Chebyshev points of 1st kind are being used.')
prefs.resampling = true;
end
else
error('CHEBFUN:chebfunpref:argin','Check number of input arguments.')
end
function prefs = initPrefs()
prefs.splitting = false;
prefs.minsamples = 9;
prefs.maxdegree = 2^16;
prefs.maxlength = 6000;
prefs.splitdegree = 128;
prefs.resampling = false;
prefs.domain = [-1 1];
prefs.eps = 2^-52;
prefs.sampletest = true;
prefs.blowup = false;
prefs.chebkind = 2;
prefs.extrapolate = false;
prefs.plot_numpts = 2001;
prefs.polishroots = false;
prefs.ADdepth = 25;
% Note: The proper number of points for Chebyshev points of the first kind
% is 2^k (not 2^k+1 as for the second kind).