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

Changed implementation of function handles for constant symbolics in quantity.Symbolic.

parent 25807034
......@@ -170,7 +170,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
valueDiscrete = obj.valueDiscrete;
end
%-------------------
% --- converters ---
%-------------------
......@@ -583,20 +583,20 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
end
function obj = sort(obj, varargin)
function newObj = sort(obj, varargin)
%SORT sorts the grid of the object in a desired order
% obj = sortGrid(obj) sorts the grid in alphabetical order.
% obj = sort(obj, 'descend') sorts the grid in descending
% alphabetical order.
newObj = obj.copy();
% only sort the grids if there is something to sort
if ~isempty(obj) && obj(1).nargin > 1
if ~isempty(newObj) && newObj(1).nargin > 1
[sortedDomain, I] = obj(1).domain.sort(varargin{:});
[obj.domain] = deal(sortedDomain);
[sortedDomain, I] = newObj(1).domain.sort(varargin{:});
[newObj.domain] = deal(sortedDomain);
for k = 1:numel(obj)
obj(k).valueDiscrete = permute(obj(k).valueDiscrete, I);
for k = 1:numel(newObj)
newObj(k).valueDiscrete = permute(obj(k).valueDiscrete, I);
end
end
end% sort()
......
......@@ -113,7 +113,7 @@ classdef Function < quantity.Discrete
% number of input values.
n = numel(obj(1).grid);
end % nargin()
end
end % methods
% -------------
% --- Mathe ---
......
......@@ -41,7 +41,6 @@ classdef Symbolic < quantity.Function
fun = cell(S{:});
symb = cell(S{:});
for k = 1:numel(valueContinuous)
if iscell(valueContinuous)
......@@ -849,12 +848,13 @@ classdef Symbolic < quantity.Function
end
end % getVariable()
function f = setValueContinuous(f, symVar)
function [f, argList] = setValueContinuous(f, symVar)
% converts symVar into a matlabFunction.
argList = string(symVar);
if isa(f, 'sym')
if isempty(symvar(f))
fDouble = double(f);
f = @(varargin) fDouble + quantity.Function.zero(varargin{:});
f = eval("@(" + argList + ") fDouble + quantity.Function.zero(varargin{:})");
else
if iscell( symVar )
symVar = [symVar{:}];
......@@ -865,4 +865,4 @@ classdef Symbolic < quantity.Function
end
end % setValueContinuous()
end % methods (Static, Access = protected)
end % classdef
\ No newline at end of file
end % classdef
......@@ -8,11 +8,18 @@ function testValueContinuousBug(tc)
z = quantity.Domain("z", linspace(0, 1, 7));
zeta = quantity.Domain("zeta", linspace(0, 1, 5));
A = quantity.Symbolic(sin(sym("z") * pi), z);
B = [0*z.Symbolic + zeta.Symbolic, A + 0*zeta.Symbolic; ...
B1 = [0*z.Symbolic + zeta.Symbolic, A + 0*zeta.Symbolic; ...
z.Symbolic+zeta.Symbolic, A * subs(A, "z", "zeta")];
B2 = [zeta.Symbolic + 0*z.Symbolic, A + 0*zeta.Symbolic; ...
z.Symbolic+zeta.Symbolic, A * subs(A, "z", "zeta")];
tc.verifyEqual(B.on([z, zeta]), B2.on([z, zeta]));
tc.verifyEqual(B1.on([z, zeta]), B2.on([z, zeta]));
C1 = [0*z.Symbolic + zeta.Symbolic, A + 0*zeta.Symbolic];
c1 = zeta.Symbolic + 0*z.Symbolic;
c2 = A + 0*zeta.Symbolic;
C2 = [c1, c2];
tc.verifyEqual(C1.on([z, zeta]), C2.on([z, zeta]));
% TODO: fix this error! See issue #41
% this problem is maybe caused as input arguments of B2(1).valueContinuous is somehow ordered
% differently compared to B2(2:4).valueContinuous or all B(:).valueContinuous,
......
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