[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: interp1 - bug

From: Jaroslav Hajek
Subject: Re: interp1 - bug
Date: Sat, 12 Sep 2009 21:33:06 +0200

On Sat, Sep 12, 2009 at 1:48 PM, Søren Hauberg <address@hidden> wrote:
> lør, 12 09 2009 kl. 13:41 +0200, skrev Roberto Abuter:
>> I guess it is just a difference in behavior between Matlab and Octave.
>> one can always reshuffle (X,Y) in such a way X becames monotonic.
> Is there any particular reason why we are not doing this in 'interp1'?
> Couldn't just add
>  [x, idx] = sort (x);
>  y = y (idx);
> to 'interp1' ?
> Søren

Another reason is performance. At least for the default linear
interpolation, interpolating a single point in a table of length N
costs O(log(N)). By always first sorting the table you would degrade
that to O(N). This is precisely why for a binary search, you normally
"trust" the table to be sorted - checking for that would often defeat
the purpose of binary search in the first place (not always, but

RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic

reply via email to

[Prev in Thread] Current Thread [Next in Thread]