-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheboppref.m
120 lines (112 loc) · 3.83 KB
/
cheboppref.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
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
function varargout = cheboppref(varargin)
% CHEBOPPREF Settings for chebops.
%
% By itself, CHEBOPPREF returns a structure with current preferences as
% fields/values. Use it to find out what preferences are available.
%
% CHEBOPPREF(PREFNAME) returns the value corresponding to the preference
% named in the string PREFNAME.
%
% CHEBOPPREF('factory') restore all preferences to their factory defined
% values.
%
% CHEBOPPREF(PREFNAME,PREFVAL) sets the preference PREFNAME to the value
% PREFVAL. S = CHEBOPPREF(PREFNAME,PREFVAL) stores the current state of
% cheboppref in the structure S before PREFNAME is changed.
%
% CHEBOP PREFERENCES
%
% maxdegree - maximum matrix size used in linear chebop calculations
%
% storage - controls whether matrix LU factorizations are saved to speed
% up later calculations.
%
% maxstorage - max memory devoted to storage
%
% display - controls information displayed during nonlinear solution
% 'none' (default)
% 'iter' - plot iterates and updates during solution process
% 'final' - plot solution at end
%
% plotting - controls whether the most current solution and update of the
% iteratation are plotted
% 'off' - no plotting (default)
% 'on' - plots and pauses for the default time (0.5s)
% time - current iteration and update are plotted for a value of time,
% i.e., cheboppref('plotting',1) shows the plots for 1s.
% 'pause' - pauses the run of the program after plots are shown to wait
% for user action.
%
% restol - tolerance of norm of residual relative to norm of solution
%
% deltol - tolerance of norm of update relative to norm of solution
%
% (Convergence occurs if either of the above two norms are below tolerance)
%
% damped - controls method of nonlinear solution
% 'off' - pure Newton iteration (perhaps less robust; more interesting!)
% 'on' - damped Newton iteration (perhaps more robust; default)
%
% maxiter - maximum number of iterations allowed in nonlinear iteration
%
% maxstagnation - number of steps with little improvement used to define
% stagnation in damped Newton iteration
%
% See also chebfunpref.
% Copyright 2011 by The University of Oxford and The Chebfun Developers.
% See http://www.maths.ox.ac.uk/chebfun/ for Chebfun information.
persistent prefs
if isempty(prefs) % First call; get default values
prefs = initPrefs();
end
if nargout == 1
varargout = {prefs};
end
if nargin == 0 % Return structure
varargout = { prefs };
elseif nargin == 1 % Return value
if isstruct(varargin{1})
% Assign prefs from structure input
prefs = varargin{1};
return
end
prop = varargin{1};
if strcmpi(prop,'factory')
prefs = initPrefs;
elseif ~isfield(prefs,prop)
error('CHEBFUN:cheboppref:unknown','Unknown property %s', prop);
else
varargout = { prefs.(varargin{1}) };
end
else % Set value
while ~isempty(varargin) % Loop to allow setting of multiple properties
prop = lower(varargin{1}); newVal = varargin{2}; varargin(1:2) = [];
switch prop
case 'tol'
prefs.restol = newVal;
prefs.deltol = newVal;
case 'plotting'
if strcmp(newVal,'on')
prefs.plotting = 0.5;
else
prefs.plotting = newVal;
end
otherwise
if ~isfield(prefs,prop)
error('CHEBFUN:cheboppref:unknown','Unknown property %s', prop);
end
prefs.(prop) = newVal;
end
end
end
function prefs = initPrefs()
prefs.maxdegree = 1449;
prefs.storage = true;
prefs.maxstorage = 50e6;
prefs.display = 'none';
prefs.plotting = 'off';
prefs.restol= 1e-10;
prefs.deltol = 1e-10;
prefs.damped = 'on';
prefs.maxiter = 25;
prefs.maxstagnation = 5;