Commit 73524500 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Fixed derivatices of gevrey functions

parent 703ce62c
......@@ -27,6 +27,10 @@ properties (Dependent)
dt;
end
properties (Hidden)
derivatives;
end
methods
%% CONSTRUCTOR
function obj = BasicVariable(valueContinuous, varargin)
......@@ -41,24 +45,32 @@ function obj = BasicVariable(valueContinuous, varargin)
preParser.addParameter('N_t', 101);
preParser.addParameter('dt', []);
preParser.addParameter('N_diff', 1);
preParser.addParameter('t', []);
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
elseif ~isempty(preParser.Results.t)
N_t = numel( preParser.Results.t );
preResults.T = preParser.Results.t(end);
preResults.dt = preParser.Results.t(2) - preParser.Results.t(1);
elseif ~isempty(preParser.Results.N_t)
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;
else
error('No time domain specified!')
end
preResults.N_diff = preParser.Results.N_diff;
prsr = misc.Parser();
prsr.addParameter('grid', {linspace(0, preParser.Results.T, N_t)'} );
prsr.addParameter('gridName', {'t'});
prsr.parse(varargin{:});
preParserUnmateched = misc.struct2namevaluepair(preParser.Unmatched);
prsr.parse(preParserUnmateched{:});
uargin = misc.struct2namevaluepair(prsr.Unmatched);
pargin = misc.struct2namevaluepair(prsr.Results);
......@@ -79,7 +91,7 @@ function obj = BasicVariable(valueContinuous, varargin)
obj.(parameter{1}) = p1.Results.(parameter{1});
end
for parameter = fieldnames(preResults)'
obj.(parameter{1}) = preParser.Results.(parameter{1});
obj.(parameter{1}) = preResults.(parameter{1});
end
obj.derivatives = obj;
......@@ -87,30 +99,46 @@ function obj = BasicVariable(valueContinuous, varargin)
end
function D = diff(obj, K)
% DIFF compute the K-th derivative of obj
%
%
if nargin == 1
i = 1;
K = 1;
end
for j = 1:numel(obj)
objj = obj(j);
% for each requested derivative:
for i = 1:numel(K)
k = K(i);
if size(objj.derivatives, 1) < k+1 || isempty(objj.derivatives(k+1,:))
% create a new object for the derivative of obj:
D = objj.copy();
[D.name] = deal(['d/dt (' num2str(k) ') ']);
[D.valueDiscrete] = deal([]);
for l = 1:numel(objj)
D(l).diffShift = D(l).diffShift + k;
% for each component of this object:
for j = 1:numel(obj)
obj_j = obj(j);
% check if the derivative is not yet already computed:
if size(obj_j.derivatives, 1) < k+1 || isempty(obj_j.derivatives(k+1,:))
% create a new object for the derivative of obj:
Dij = obj_j.copy();
Dij.name = ['d/dt (' num2str(k) ') '];
Dij.valueDiscrete = [];
Dij.diffShift = Dij.diffShift + k;
% sort the created derivative into the list of computed
% derivatives
obj_j.derivatives(k+1,j) = Dij;
% call the function to evaluate the numerical values of
% this derivative
Dij.valueDiscrete;
Di(j) = Dij;
else % the derivative is already computed -> take this one:
Di(j) = obj_j.derivatives(k+1);
end
objj.derivatives(k+1,:) = D;
D.valueDiscrete;
else
D(:,i) = objj.derivatives(k+1,:);
end
Di = reshape(Di, [ 1 size(obj)]);
D(i,:) = Di;
end
end
end
%% PROPERTIES
......
......@@ -5,10 +5,6 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% Name of the domains that generate the grid.
gridName {mustBe.unique};
% In this cell, already computed derivatives can be stored to avoid
% multiple computations of the same derivative.
derivatives;
end
properties (Hidden, Access = protected, Dependent)
......@@ -1060,7 +1056,9 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
hold off;
end
if obj.nargin() == 0
if isempty(obj(rowIdx, columnIdx, figureIdx))
warning('you are trying to plot an empty quantity');
elseif obj.nargin() == 0
plot(0, ...
obj(rowIdx, columnIdx, figureIdx).valueDiscrete, ...
additionalPlotOptions{:});
......@@ -1214,7 +1212,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
for it = 1 : numel(obj)
newObj(it).valueDiscrete = obj(it).on(myGrid);
end
[newObj.derivatives] = deal({});
%[newObj.derivatives] = deal({});
[newObj.grid] = deal(myGrid);
end
......
......@@ -149,7 +149,6 @@ classdef Function < quantity.Discrete
end
[mObj.name] = deal(['-' obj.name]);
[mObj.derivatives] = deal({}); % #FIXME copy derivatives
end
function p = inner(A, B)
......
......@@ -7,6 +7,19 @@ end
function testBasicVariableInit(testCase)
%%
b = quantity.BasicVariable(@signals.gevrey.bump.g, 'order', 1.8, 'N_t', 101, 'T', 1);
t = linspace(0, 1, 11)';
g1 = signals.GevreyFunction('order', 1.8, 't', t);
g2 = signals.GevreyFunction('order', 1.5, 't', t);
G = [g1; g2];
N_diff = 2;
derivatives = G.diff(0:N_diff);
GD = zeros(length(t), N_diff+1, 2);
for k = 1:N_diff+1
GD(:, k, 1) = signals.gevrey.bump.g(t, k-1, t(end), g1.sigma);
GD(:, k, 2) = signals.gevrey.bump.g(t, k-1, t(end), g2.sigma);
end
testCase.verifyEqual(derivatives.on(), GD);
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment