From: Bruno Luong on
What about this test:

% Test array
a = 0:0.1:10;

equiv = norm(linspace(a(1),a(end),length(a))-a) <= eps(single(norm(a)))

Bruno
From: Jan Simon on
Dear Cesare,

> I don't know if this is related, however I've noticed that for
> x = start:step:stop;
> d = x(2:end) - x(1:end-1);
> e = eps(d);
> then unique(e) is tipically (well at least for my random tests) a scalar. I was wondering whether an observation like this or some other idea could be used to set the smallest possible threshold for determining whether x could be of the form start:step:stop.

The method used in INTERP1, Matlab 6.5, to determine equally spaced input:
eqsp = (norm(diff(x), Inf) < eps*norm(x, Inf));
Matlab 2009a:
h = diff(x);
eqsp = (norm(diff(h), Inf) <= eps(norm(x, Inf)));
if any(~isfinit(x)), eqsp = 0; end
??? Is it correct to check the norm of DIFF(h) instead of DIFF(x) ???

Good luck, Jan
From: Cesare on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i11ej1$qjs$1(a)fred.mathworks.com>...
> Dear Cesare,
>
> > I don't know if this is related, however I've noticed that for
> > x = start:step:stop;
> > d = x(2:end) - x(1:end-1);
> > e = eps(d);
> > then unique(e) is tipically (well at least for my random tests) a scalar. I was wondering whether an observation like this or some other idea could be used to set the smallest possible threshold for determining whether x could be of the form start:step:stop.
>
> The method used in INTERP1, Matlab 6.5, to determine equally spaced input:
> eqsp = (norm(diff(x), Inf) < eps*norm(x, Inf));
> Matlab 2009a:
> h = diff(x);
> eqsp = (norm(diff(h), Inf) <= eps(norm(x, Inf)));
> if any(~isfinit(x)), eqsp = 0; end
> ??? Is it correct to check the norm of DIFF(h) instead of DIFF(x) ???
>
> Good luck, Jan

Thank you very much Jan, it is very interesting and it seems to work. Now I'm trying to understand the rationale behind it. Since norm(x,Inf) = max(abs(x)) they are essentially comparing max(abs(diff(h))), which makes sense, with eps(max(abs(x))). In this second term, what I don't understand is why they take the eps of the max rather than the max of the eps. Do the largest values also have the largest eps error?
Thanks again,
Cesare
From: Steven Lord on

"Cesare " <cmfornewsgroup(a)gmail.com> wrote in message
news:i11ajg$90p$1(a)fred.mathworks.com...
> Greg Heath <heath(a)alumni.brown.edu> wrote in message
> <b966a3aa-216c-4c40-9429-156c7b05c0ae(a)z8g2000yqz.googlegroups.com>...
>> On Jul 6, 9:33 am, "Cesare " <cmfornewsgr...(a)gmail.com> wrote:
>> > Hi! This has probably been asked several time however I couldn't find a
>> > post about it.
>> > I need to check whether an input array is equispaced. However
>> >
>> > x = 0.01:0.1:0.51;
>> > d = x(2:end) - x(1:end-1);
>> >
>> > won't result in a single valued unique(x) because of numerical errors.
>> > What is the best way to tackle this problem?
>> > Many thanks in advance,
>> > Cesare
>>
>> N = length(x)
>> dx = (x(end)-x(1))/(N-1)
>> xnew = dx*(0:N-1);
>>
>> Hope this helps.
>>
>> Greg
>
>
> Dear Greg and "someone",
> many thanks for your replies. Unfortunately I cannot ask the users of my
> function to input arrays that are built so that the numerical error does
> not show out. They'll generate x = start:step:stop and my function must be
> able to interpret is as an equispaced array correctly. Obviously, as
> Steven pointed out, one needs to set a tolerance. However I'm wondering
> whether for arrays generated as start:step:stop there is an "intrinsic"
> tolerance level that can be estimated. I don't know if this is related,
> however I've noticed that for

Rather than asking your users for a vector x (thereby opening up the
possibility for your users to specify a vector that doesn't meet your needs)
why not ask them for the three quantities start, step, and stop and build
the vector yourself, thus ensuring it meets your requirements?

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: John D'Errico on
"someone" <someone(a)somewhere.net> wrote in message <i0vbt7$lli$1(a)fred.mathworks.com>...
> "Cesare " <cmfornewsgroup(a)gmail.com> wrote in message <i0vbah$dc3$1(a)fred.mathworks.com>...
> > Hi! This has probably been asked several time however I couldn't find a post about it.
> > I need to check whether an input array is equispaced. However
> >
> > x = 0.01:0.1:0.51;
> > d = x(2:end) - x(1:end-1);
> >
> > won't result in a single valued unique(x) because of numerical errors. What is the best way to tackle this problem?
> > Many thanks in advance,
> > Cesare
>
> % One solution:
>
> x = 1:10:51;
> d = (x(2:end) - x(1:end-1))/100;

This does not help to TEST if a vector is equally spaced.

John