view isEquidistant.m @ 841:006defd0247b

Fix bug in +scheme.bcSetup outputs of parseDate(...) were not set correctly which caused a chrash in the case when no data was provided for the BC
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 20 Sep 2018 11:45:40 +0200
parents b43c4d841afe
children
line wrap: on
line source

% Tests if consecutive elements of vector v are euidistant
function b = isEquidistant(v)
    if length(v) < 2
        error('sbplib:isEquidistant:inputTooShort', 'Input vector is too short');
    end

    tol = 1e-8;

    d = v(2:end) - v(1:end-1);
    err = abs(d - d(1));

    relErr = err./abs(d);

    I_zero = find(d < tol);

    relErr(I_zero) = err(I_zero);

    b = all(relErr < tol);
end