BasicVariable.m 4.62 KB
 1 ``````classdef BasicVariable < quantity.Function `````` Ferdinand Fischer committed May 23, 2019 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 `````` %BasicVariable class for desription of basic variables % The basic variable can be of the form % g(t) = [phi_1(t); phi(2); ... ] % properties % The constant gain of the Gevrey-function K double = 1; % Shifts the evaluation of the derivative of the Gevrey-function. % Can be used if the series, computed using the gevrey function, % should not start at the 0-th derivative. diffShift double {mustBeNonnegative, mustBeInteger}; % Offset to raise the whole Gevrey-function g_ = g + offset. offset double; % Number of discretization points for the time variable at which % the Gevrey-function is evaluated. N_t double; % Number of derivatives that need to be considered for this gevrey % function N_diff double; % Length of the time interval the Gevrey-function is defined on. T double = -1; % Gevrey-order order double = -1; end properties (Dependent) sigma; dt; end methods %% CONSTRUCTOR function obj = BasicVariable(valueContinuous, varargin) parentVarargin = {}; if nargin > 0 % make default grid: preParser = misc.Parser(); preParser.addParameter('T', 1); preParser.addParameter('N_t', 101); preParser.addParameter('dt', []); preParser.addParameter('N_diff', 1); preParser.parse(varargin{:}); if ~isempty(preParser.Results.dt) N_t = quantity.BasicVariable.setDt(preParser.Results.T, preParser.Results.dt); preResults.T = preParser.Results.T; preResults.dt = preParser.Results.dt; preResults.N_diff = preParser.Results.N_diff; else N_t = preParser.Results.N_t; preResults.T = preParser.Results.T; preResults.N_t = preParser.Results.N_t; preResults.N_diff = preParser.Results.N_diff; end grid = {linspace(0, preParser.Results.T, N_t)'}; varargin = [varargin{:}, 'grid', {grid}]; parentVarargin = {valueContinuous, varargin{:}, 'gridName', {'t'}}; end obj@quantity.Function(parentVarargin{:}); if nargin > 0 % first parser p1 = misc.Parser(); p1.addParameter('K', 1); p1.addParameter('diffShift', 0); p1.addParameter('offset', 0); p1.addParameter('order', 1.5); p1.parse(varargin{:}); for parameter = fieldnames(p1.Results)' obj.(parameter{1}) = p1.Results.(parameter{1}); end for parameter = fieldnames(preResults)' obj.(parameter{1}) = preParser.Results.(parameter{1}); end end end function n = nargin(obj) n = 1; end function D = diff(obj, K) if nargin == 1 i = 1; end for i = 1:numel(K) % create a new object for the derivative of obj: D(:,i) = obj.copy(); [D.name] = deal(['d/dt (' num2str(K(i)) ') ']); [D.valueDiscrete] = deal([]); for l = 1:numel(obj) D(l,i).diffShift = D(l, 1).diffShift + K(i); end end end %% PROPERTIES function dt = get.dt(obj) dt = obj.T / obj.N_t; end function set.dt(obj, dt) obj.N_t = quantity.BasicVariable.setDt(obj.T, dt); end function obj = set.diffShift(obj, n) obj.diffShift = n; obj.valueDiscrete = []; end function s = get.sigma(obj) s = 1 / ( obj.order - 1); end function obj = set.sigma(obj, s) obj.order = 1 + 1/s; end function obj = set.order(obj, order) obj.order = obj.set_order(order); end function order = get.order(obj) order = obj.get_order(obj.order); end function obj = set.N_t(obj, value) obj.N_t = obj.set_N_t(value); end function N = get.N_t(obj) N = obj.get_N_t(obj.N_t); end function obj = set.T(obj, value) obj.T = obj.set_T(value); end function T = get.T(obj) T = obj.get_T(obj.T); end function b = copy_K(obj, K) b = obj.copy(); b.valueDiscrete = K / obj.K * obj.valueDiscrete(); b.K = K; end end methods (Access = protected) function f = getValueContinuous(obj, f) f = @(z) obj.K * f(z, obj.diffShift, obj.T, obj.sigma); end function order = set_order(obj, order) end function order = get_order(obj, order) end function T = get_T(obj, T) end function T = set_T(obj, T) end function n = get_n(obj, n) end function n = set_n(obj, n) end function N = get_N_t(obj, N) end function N = set_N_t(obj, N) end end methods (Access = protected, Static) function Nt = setDt(T, dt) t = 0:dt:T; Nt = length(t); if ~numeric.near(t(end), T) warning(['Sampling with dt=' num2str(dt) ' leads to t(end)= ' num2str(t(end))]); end end end methods (Static) function b = makeBasicVariable(b0, K) for k = 1:numel(K) for l = 1:size(b0, 2) b(k, l) = b0(l).copy_K(K(k)); end end end end `````` 199 ``end``