Commit 451a8d40 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

.at() for Function (and implicitly for Symbolic) - faster and more precise

parent af58bb0f
......@@ -93,6 +93,21 @@ classdef Function < quantity.Discrete
end
end % obj2value()
function value = at(obj, point)
% at() evaluates the object at one point and returns it as array
% with the same size as size(obj).
value = zeros(size(obj));
if ~iscell(point)
for it = 1 : numel(value)
value(it) = obj(it).valueContinuous(point);
end
else
for it = 1 : numel(value)
value(it) = obj(it).valueContinuous(point{:});
end
end
end % at()
function n = nargin(obj)
% FIXME: check if all funtions in this object have the same
% number of input values.
......
......@@ -4,6 +4,17 @@ function [tests] = testFunction()
tests = functiontests(localfunctions);
end
function testAt(tc)
z = quantity.Domain("z", linspace(0, 1, 11));
f = quantity.Function({@(z)sin(z), @(z)1+z; @(z)cos(z), @(z)z.^2}, z);
fZZeta = quantity.Function({@(z,zeta)sin(zeta)+z, @(z,zeta)1+zeta-z; @(z,zeta)cos(z), @(z,zeta)zeta.^2}, ...
[z, z.rename("zeta")]);
fDisc = quantity.Discrete(f);
tc.verifyLessThan(abs(f.at({0.2}) - fDisc.at({0.2})), 10*eps);
fZZetaDisc = quantity.Discrete(fZZeta);
tc.verifyLessThan(abs(fZZeta.at({0.2, 0.4}) - fZZetaDisc.at({0.2, 0.4})), 10*eps);
end % testAt()
function testInt(testCase)
z = quantity.Domain("z", linspace(0,1));
......
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