octave-maintainers
[Top][All Lists]
Advanced

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

Re: Should interp1.m function allow jumps in X-values?


From: vivek dogra
Subject: Re: Should interp1.m function allow jumps in X-values?
Date: Tue, 21 Aug 2012 18:56:39 +0530

On Tue, Aug 21, 2012 at 6:30 PM, Michael D Godfrey <address@hidden> wrote:
On 08/21/2012 08:57 AM, vivek dogra wrote:
Although if it has identical values then it is always favoring increasing order
I think you need to read the code again taking into account:

octave:1> X = [ 1 2 2 3];
octave:2> issorted(X)
ans =  1


Sorry i am not able to make myself clear. My understanding of the code is as follows:

 ## check whether x is sorted; sort if not.
  if (! issorted (x, "either"))                                             ## Check if X is sorted either in ascending or descending order.
    [x, p] = sort (x);                                                         ##  If it is not sorted, sort it  ("X is sorted in ascending order by default")
    y = y(p,:);
  endif

My point:
1st case: X having distinct values, everything is alright!

2nd case: X is increasing or decreasing (sorted) and X has at most one identical pair. interp1 gives answer as mentioned in the documentation.

3rd case: X is neither increasing nor decreasing (unsorted) and have identical values ==> Octave will always sort it in ascending order.

In the following example which is 3rd case (X is unsorted and and have identical values):

X = [ 2 1 3 2];
Y = [ 2 1 3 10];                               # i get 10 because of some error in an experiment

Now because Octave will always sort it in ascending order, i.e. After sorting:
X = [ 1 2 2 3];
Y = [ 1 2 10 3];

Now as X is increasing now it is right continuous therefore to interpolate Octave will use value of 2 as 10, which is incorrect. (Octave has decided for the user)

Please reply to this situation. I would like to have a discussion on what will happen in some practical situation like this?

reply via email to

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